Demographic Data:

cat <- data.table::fread(here::here("data", "DemographicCategories.csv"))

Template Data Analysis:

# Load The Data:
dt <- data.table::fread(here::here("data", "CGCS-Template.csv"))
head(dt)
##    Source eType Target   Time Weight SourceLocation TargetLocation
## 1:      0     4    -99    -99    -99             NA             NA
## 2:     41     0     34  86400      1             NA             NA
## 3:     37     0     27  94461      1             NA             NA
## 4:     34     1     27 107548      1              5              5
## 5:     41     0     37 127838      1             NA             NA
## 6:     34     1     37 137358      1              5              5
##    SourceLatitude SourceLongitude TargetLatitude TargetLongitude
## 1:             NA              NA             NA              NA
## 2:             NA              NA             NA              NA
## 3:             NA              NA             NA              NA
## 4:             NA              NA             NA              NA
## 5:             NA              NA             NA              NA
## 6:             NA              NA             NA              NA
tail(dt)
##    Source eType Target     Time Weight SourceLocation TargetLocation
## 1:      0     5 571970 31536000     80             NA             NA
## 2:      0     5 644226 31536000   1000             NA             NA
## 3:      0     5 473173 31536000   1000             NA             NA
## 4:      0     5 620120 31536000    800             NA             NA
## 5:      0     5 575030 31536000   2000             NA             NA
## 6:      0     5 621924 31536000   1000             NA             NA
##    SourceLatitude SourceLongitude TargetLatitude TargetLongitude
## 1:             NA              NA             NA              NA
## 2:             NA              NA             NA              NA
## 3:             NA              NA             NA              NA
## 4:             NA              NA             NA              NA
## 5:             NA              NA             NA              NA
## 6:             NA              NA             NA              NA
# Summarising the Data:
summary(dt)
##      Source           eType           Target            Time         
##  Min.   :     0   Min.   :0.000   Min.   :   -99   Min.   :     -99  
##  1st Qu.:    39   1st Qu.:1.000   1st Qu.:    44   1st Qu.:14005495  
##  Median :    45   Median :5.000   Median :    72   Median :31536000  
##  Mean   : 26210   Mean   :3.068   Mean   :274951   Mean   :23667653  
##  3rd Qu.:    59   3rd Qu.:5.000   3rd Qu.:575030   3rd Qu.:31536000  
##  Max.   :620120   Max.   :6.000   Max.   :657187   Max.   :31536000  
##                                                                      
##      Weight       SourceLocation  TargetLocation  SourceLatitude
##  Min.   :   -99   Min.   :0.000   Min.   :0.000   Mode:logical  
##  1st Qu.:     1   1st Qu.:3.000   1st Qu.:3.000   NA's:1325     
##  Median :    70   Median :5.000   Median :4.000                 
##  Mean   :  1941   Mean   :3.861   Mean   :3.585                 
##  3rd Qu.:  1000   3rd Qu.:5.000   3rd Qu.:5.000                 
##  Max.   :200000   Max.   :5.000   Max.   :5.000                 
##                   NA's   :1024    NA's   :1024                  
##  SourceLongitude TargetLatitude TargetLongitude
##  Mode:logical    Mode:logical   Mode:logical   
##  NA's:1325       NA's:1325      NA's:1325      
##                                                
##                                                
##                                                
##                                                
## 
nrow(dt)
## [1] 1325
ncol(dt)
## [1] 11
dt$Source <- as.character(dt$Source)
dt$Target <- as.character(dt$Target)
str(dt$Source)
##  chr [1:1325] "0" "41" "37" "34" "41" "34" "27" "27" "41" "37" "41" ...
str(dt$Target)
##  chr [1:1325] "-99" "34" "27" "27" "37" "37" "41" "41" "37" "34" "34" ...
# Differentiating between channels:
dt01 <- dt %>% filter(dt$eType == 0 | dt$eType == 1) # Communication Channel
nrow(dt01) # 563
## [1] 563
dt23 <- dt %>% filter(dt$eType == 2 | dt$eType == 3) # Procurement Channel
nrow(dt23) # 18
## [1] 18
dt4 <- dt %>% filter(dt$eType == 4) # Co-authorship Channel
nrow(dt4) # 1
## [1] 1
dt5 <- dt %>% filter(dt$eType == 5) # Demographic Channel
nrow(dt5) # 591
## [1] 691
dt6 <- dt %>% filter(dt$eType == 6) # Travel Channel
nrow(dt6) # 52
## [1] 52
# Analysis of the Communication channel:
glimpse(dt01)
## Observations: 563
## Variables: 11
## $ Source          <chr> "41", "37", "34", "41", "34", "27", "27", "41"...
## $ eType           <int> 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1...
## $ Target          <chr> "34", "27", "27", "37", "37", "41", "41", "37"...
## $ Time            <int> 86400, 94461, 107548, 127838, 137358, 137514, ...
## $ Weight          <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1...
## $ SourceLocation  <int> NA, NA, 5, NA, 5, NA, NA, 5, NA, NA, 5, 5, NA,...
## $ TargetLocation  <int> NA, NA, 5, NA, 5, NA, NA, 5, NA, NA, 5, 5, NA,...
## $ SourceLatitude  <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
## $ SourceLongitude <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
## $ TargetLatitude  <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
## $ TargetLongitude <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
#unique(dt01)
unique(dt01$eType) # 0 1
## [1] 0 1
unique(dt01$SourceLocation) # NA  5  3  4  0
## [1] NA  5  3  4  0
unique(dt01$TargetLocation) # NA  5  0  3  4
## [1] NA  5  0  3  4
unique(dt01$SourceLatitude) # NA
## [1] NA
unique(dt01$SourceLongitude) # NA
## [1] NA
unique(dt01$TargetLatitude) # NA
## [1] NA
unique(dt01$TargetLongitude) # NA
## [1] NA
unique(dt01$Source)
##  [1] "41" "37" "34" "27" "40" "65" "67" "47" "39" "43" "57" "58" "63" "56"
## [15] "45"
unique(dt01$Target)
##  [1] "34" "27" "37" "41" "0"  "39" "66" "47" "65" "40" "67" "56" "43" "57"
## [15] "58" "63" "45"
dt01 <- subset(dt01, select = -c(SourceLatitude, SourceLongitude)) # SOurce and Target Latitude and Longitude columns removed as all Null.
dt01 <- subset(dt01, select = -c(TargetLatitude, TargetLongitude))
dt01 <- subset(dt01, select = -Weight) # Weight removed as all values 1.
colnames(dt01)
## [1] "Source"         "eType"          "Target"         "Time"          
## [5] "SourceLocation" "TargetLocation"
any(dt01$Source) == any(dt01$Target) # True
## Warning in any(dt01$Source): coercing argument of type 'character' to
## logical
## Warning in any(dt01$Target): coercing argument of type 'character' to
## logical
## [1] NA
range(dt01$Source) # 27-67
## [1] "27" "67"
range(dt01$Target) # 0-67
## [1] "0"  "67"
range(dt01$Time) # 86400-27222388
## [1]    86400 27222388
# Analysis of the Demographic channel:
glimpse(dt5)
## Observations: 691
## Variables: 11
## $ Source          <chr> "2", "2", "510031", "2", "552988", "2", "2", "...
## $ eType           <int> 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5...
## $ Target          <chr> "630626", "536346", "2", "520660", "2", "56719...
## $ Time            <int> 31536000, 31536000, 31536000, 31536000, 315360...
## $ Weight          <int> 5000, 1000, 600, 3000, 40000, 4000, 100, 900, ...
## $ SourceLocation  <int> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
## $ TargetLocation  <int> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
## $ SourceLatitude  <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
## $ SourceLongitude <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
## $ TargetLatitude  <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
## $ TargetLongitude <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
#unique(dt5)
unique(dt5$eType) # 5
## [1] 5
unique(dt5$SourceLocation) # NA
## [1] NA
unique(dt5$TargetLocation) # NA 
## [1] NA
unique(dt5$SourceLatitude) # NA
## [1] NA
unique(dt5$SourceLongitude) # NA
## [1] NA
unique(dt5$TargetLatitude) # NA
## [1] NA
unique(dt5$TargetLongitude) # NA
## [1] NA
unique(dt5$Source) 
##  [1] "2"      "510031" "552988" "27"     "29"     "31"     "33"    
##  [8] "34"     "35"     "36"     "620120" "37"     "38"     "39"    
## [15] "40"     "41"     "42"     "43"     "44"     "45"     "46"    
## [22] "47"     "48"     "49"     "52"     "53"     "54"     "55"    
## [29] "56"     "57"     "58"     "59"     "60"     "61"     "62"    
## [36] "63"     "64"     "65"     "0"
unique(dt5$Target)
##  [1] "630626" "536346" "2"      "520660" "567195" "527449" "459381"
##  [8] "595298" "466907" "589943" "577992" "537281" "523927" "580426"
## [15] "595581" "642329" "503701" "571970" "644226" "632961" "473173"
## [22] "620120" "621924" "27"     "616315" "29"     "575030" "503218"
## [29] "31"     "33"     "34"     "35"     "36"     "37"     "38"    
## [36] "39"     "40"     "41"     "42"     "43"     "44"     "45"    
## [43] "46"     "47"     "48"     "640784" "49"     "606730" "52"    
## [50] "53"     "54"     "55"     "56"     "57"     "58"     "59"    
## [57] "60"     "61"     "62"     "63"     "64"     "65"     "0"
unique(dt5$Weight)
##  [1]   5000   1000    600   3000  40000   4000    100    900   2000    400
## [11]    200     20    500     10    700   6000  50000     50    800    300
## [21]   9000  30000   8000     70  10000     40     30     80  20000     60
## [31]     90 200000   7000      2      7 100000      3      6
dt5 <- subset(dt5, select = -c(SourceLocation, TargetLocation, SourceLatitude, SourceLongitude, TargetLatitude, TargetLongitude)) # SOurce and Target Latitude and Longitude columns removed as all Null.
colnames(dt5)
## [1] "Source" "eType"  "Target" "Time"   "Weight"
#any(dt5$Source) == any(dt5$Target) # True
range(dt5$Source) # 0-620120
## [1] "0"  "65"
range(dt5$Target) # 0-644226
## [1] "0"  "65"
range(dt5$Time) # 31536000-31536000
## [1] 31536000 31536000
income_cat <- subset(dt5$Source, dt5$Source >= 500000)
unique(income_cat) #Income Categories: 510031(Gifts), 552988(Money Income before Taxes), 620120(Personal Taxes)
## [1] "620120" "60"     "61"     "62"     "63"     "64"     "65"
expense_cat <- subset(dt5$Target, dt5$Target >= 500000)
sort(unique(expense_cat)) # Expense Categories: 503218(Natural Gas) 503701(Miscellaneous) 520660(Healthcare) 523927(Restaurants) 527449 (Alcohol) 
##  [1] "60"     "606730" "61"     "616315" "62"     "620120" "621924"
##  [8] "63"     "630626" "632961" "64"     "640784" "642329" "644226"
## [15] "65"
                                  # 536346(Home Maintenance) 537281(HouseKeeping) 567195 (Personal insurance and pensions) 
                                  # 571970(Reading) 575030 (Transportation) 577992 (Education) 580426 (Telephone services) 
                                  # 589943(Lodging away from home) 595298(Groceries) 595581(Donations) 606730(Entertainment)
                                  # 616315(Apparel and services) 620120(Personal taxes) 621924(Mortgage payments) 
                                  # 630626(Rented dwellings) 632961(Personal care products and services) 
                                  # 640784(Tobacco) 642329(Household operations) 644226(Property taxes)

hist(dt5$Weight)

unique(dt5$Weight)
##  [1]   5000   1000    600   3000  40000   4000    100    900   2000    400
## [11]    200     20    500     10    700   6000  50000     50    800    300
## [21]   9000  30000   8000     70  10000     40     30     80  20000     60
## [31]     90 200000   7000      2      7 100000      3      6
range(dt5$Weight) #2-200000
## [1]      2 200000
# Income Categories:
dt5_sub1 <- subset(dt5, dt5$Source >= 500000) # Subset of data with only income categories
str(dt5_sub1)
## 'data.frame':    114 obs. of  5 variables:
##  $ Source: chr  "620120" "620120" "620120" "620120" ...
##  $ eType : int  5 5 5 5 5 5 5 5 5 5 ...
##  $ Target: chr  "36" "37" "38" "40" ...
##  $ Time  : int  31536000 31536000 31536000 31536000 31536000 31536000 31536000 31536000 31536000 31536000 ...
##  $ Weight: int  700 800 400 300 7000 2000 200000 50 300 600 ...
plot(dt5_sub1$Source, dt5_sub1$Weight) # Plot of Monetary income in each category

# Expense Categories:
dt5_sub2 <- subset(dt5, dt5$Target >= 500000) # Subset of data with only expense categories
str(dt5_sub2)
## 'data.frame':    180 obs. of  5 variables:
##  $ Source: chr  "2" "2" "2" "2" ...
##  $ eType : int  5 5 5 5 5 5 5 5 5 5 ...
##  $ Target: chr  "630626" "642329" "644226" "632961" ...
##  $ Time  : int  31536000 31536000 31536000 31536000 31536000 31536000 31536000 31536000 31536000 31536000 ...
##  $ Weight: int  5000 1000 500 10 5000 700 6000 800 2000 800 ...
plot(dt5_sub2$Target, dt5_sub2$Weight) # Plot of Monetary expenses in each category

#any(dt6$Source) == any(dt6$Target)

Graph 1 Analysis:

qt1 <- data.table::fread(here::here("data", "Q1-Graph1.csv"))
head(qt1)
##    Source eType Target       Time   Weight SourceLocation TargetLocation
## 1: 616050     4 590502 -662041253 0.166667             NA             NA
## 2: 599956     0 635665    1296000 1.000000             NA             NA
## 3: 599956     0 490041    1306507 1.000000             NA             NA
## 4: 599956     0 490041    1312679 1.000000             NA             NA
## 5: 490041     0 599956    1314435 1.000000             NA             NA
## 6: 490041     0 599956    1331859 1.000000             NA             NA
##    SourceLatitude SourceLongitude TargetLatitude TargetLongitude
## 1:             NA              NA             NA              NA
## 2:             NA              NA             NA              NA
## 3:             NA              NA             NA              NA
## 4:             NA              NA             NA              NA
## 5:             NA              NA             NA              NA
## 6:             NA              NA             NA              NA
tail(qt1)
##    Source eType Target     Time  Weight SourceLocation TargetLocation
## 1: 533140     5 642329 31536000 1131.24             NA             NA
## 2: 533140     5 503701 31536000 1741.49             NA             NA
## 3: 533140     5 571970 31536000   85.16             NA             NA
## 4: 533140     5 632961 31536000  290.73             NA             NA
## 5: 533140     5 473173 31536000 1516.94             NA             NA
## 6: 533140     5 620120 31536000  333.78             NA             NA
##    SourceLatitude SourceLongitude TargetLatitude TargetLongitude
## 1:             NA              NA             NA              NA
## 2:             NA              NA             NA              NA
## 3:             NA              NA             NA              NA
## 4:             NA              NA             NA              NA
## 5:             NA              NA             NA              NA
## 6:             NA              NA             NA              NA
# Summarising the Data:
summary(qt1)
##      Source           eType           Target            Time           
##  Min.   :463777   Min.   :0.000   Min.   :459381   Min.   :-662041253  
##  1st Qu.:512397   1st Qu.:1.000   1st Qu.:523927   1st Qu.:  22838456  
##  Median :570411   Median :5.000   Median :577992   Median :  31536000  
##  Mean   :566372   Mean   :3.801   Mean   :566666   Mean   :  25825976  
##  3rd Qu.:616050   3rd Qu.:5.000   3rd Qu.:620120   3rd Qu.:  31536000  
##  Max.   :654981   Max.   :6.000   Max.   :657187   Max.   :  31536000  
##                                                                        
##      Weight         SourceLocation  TargetLocation  SourceLatitude   
##  Min.   :     0.2   Min.   :0.000   Min.   :0.000   Min.   :-29.000  
##  1st Qu.:     1.0   1st Qu.:0.000   1st Qu.:0.000   1st Qu.:-24.566  
##  Median :   655.2   Median :0.000   Median :2.000   Median : 27.203  
##  Mean   :  5441.3   Mean   :1.321   Mean   :1.363   Mean   :  6.367  
##  3rd Qu.:  2474.7   3rd Qu.:3.000   3rd Qu.:2.000   3rd Qu.: 34.296  
##  Max.   :900735.0   Max.   :5.000   Max.   :5.000   Max.   : 35.881  
##                     NA's   :1048    NA's   :1048    NA's   :1048     
##  SourceLongitude   TargetLatitude    TargetLongitude  
##  Min.   :-165.00   Min.   :-29.000   Min.   :-165.00  
##  1st Qu.:-110.65   1st Qu.:-22.000   1st Qu.: -48.67  
##  Median : -39.03   Median :  1.000   Median : -37.81  
##  Mean   : -31.99   Mean   :  4.171   Mean   : -17.57  
##  3rd Qu.: -34.54   3rd Qu.: 30.448   3rd Qu.:  89.42  
##  Max.   : 156.00   Max.   : 35.881   Max.   : 156.00  
##  NA's   :1048      NA's   :1048      NA's   :1048
nrow(qt1) #1216
## [1] 1216
ncol(qt1) #11
## [1] 11
qt1$Source <- as.character(qt1$Source)
qt1$Target <- as.character(qt1$Target)

# Differentiating between channels:
qt1_01 <- qt1 %>% filter(qt1$eType == 0 | qt1$eType == 1) # Communication Channel
nrow(qt1_01) # 318
## [1] 318
qt1_23 <- qt1 %>% filter(qt1$eType == 2 | qt1$eType == 3) # Procurement Channel
nrow(qt1_23) # 14
## [1] 14
qt1_4 <- qt1 %>% filter(qt1$eType == 4) # Co-authorship Channel
nrow(qt1_4) # 1
## [1] 1
qt1_5 <- qt1 %>% filter(qt1$eType == 5) # Demographic Channel
nrow(qt1_5) # 846
## [1] 846
qt1_6 <- qt1 %>% filter(qt1$eType == 6) # Travel Channel
nrow(qt1_6) # 37
## [1] 37
# Highest data for Demographic, Communication and Travel Channel.


# Analysis of the Communication channel:
glimpse(qt1_01)
## Observations: 318
## Variables: 11
## $ Source          <chr> "599956", "599956", "599956", "490041", "49004...
## $ eType           <int> 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0...
## $ Target          <chr> "635665", "490041", "490041", "599956", "59995...
## $ Time            <int> 1296000, 1306507, 1312679, 1314435, 1331859, 1...
## $ Weight          <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1...
## $ SourceLocation  <int> NA, NA, NA, NA, NA, NA, NA, NA, 0, 0, NA, 0, 0...
## $ TargetLocation  <int> NA, NA, NA, NA, NA, NA, NA, NA, 0, 0, NA, 0, 0...
## $ SourceLatitude  <dbl> NA, NA, NA, NA, NA, NA, NA, NA, 34.5741, 34.29...
## $ SourceLongitude <dbl> NA, NA, NA, NA, NA, NA, NA, NA, -42.0541, -39....
## $ TargetLatitude  <dbl> NA, NA, NA, NA, NA, NA, NA, NA, 30.4483, 29.32...
## $ TargetLongitude <dbl> NA, NA, NA, NA, NA, NA, NA, NA, -42.5341, -37....
#unique(qt1_01)
unique(qt1_01$eType) # 0 1
## [1] 0 1
unique(qt1_01$SourceLocation) # NA 0 2 3
## [1] NA  0  2  3
unique(qt1_01$TargetLocation) # NA 0 2 3
## [1] NA  0  2  3
unique(qt1_01$SourceLatitude) # NA  34.5741  34.2958 -27.2563  29.3296 -20.9062 -21.8004  25.0754 -25.4639 -24.5657 -18.3758  30.4483  35.8806
##  [1]       NA  34.5741  34.2958 -27.2563  29.3296 -20.9062 -21.8004
##  [8]  25.0754 -25.4639 -24.5657 -18.3758  30.4483  35.8806
unique(qt1_01$SourceLongitude) # NA  -42.0541  -39.0260   91.7676  -37.8076   92.3982   89.7045  -40.6293 -111.2490 -110.6500   91.0250  -42.5341  -34.5372
##  [1]        NA  -42.0541  -39.0260   91.7676  -37.8076   92.3982   89.7045
##  [8]  -40.6293 -111.2490 -110.6500   91.0250  -42.5341  -34.5372
unique(qt1_01$TargetLatitude) # NA  30.4483  29.3296  34.2958  34.5741  28.3004 -27.2563 -22.6503 -21.8004 -20.9062  25.0754 -24.5657 -20.8686 -18.3758
##  [1]       NA  30.4483  29.3296  34.2958  34.5741  28.3004 -27.2563
##  [8] -22.6503 -21.8004 -20.9062  25.0754 -24.5657 -20.8686 -18.3758
## [15]  32.6654 -25.4639 -17.1099  35.8806
                                  # 32.6654 -25.4639 -17.1099  35.8806
unique(qt1_01$TargetLongitude) # NA  -42.5341  -37.8076  -39.0260  -42.0541  -47.4036   91.7676   92.6106   89.7045   92.3982  -40.6293 -110.6500   89.4217
##  [1]        NA  -42.5341  -37.8076  -39.0260  -42.0541  -47.4036   91.7676
##  [8]   92.6106   89.7045   92.3982  -40.6293 -110.6500   89.4217   91.0250
## [15]  -48.6701 -111.2490   90.7971  -34.5372
                                        #91.0250  -48.6701 -111.2490   90.7971  -34.5372
unique(qt1_01$Source) # 599956 490041 533140 568093 632150 635665 616050 512397 623295 589639 550287 550361 596193
##  [1] "599956" "490041" "533140" "568093" "632150" "635665" "616050"
##  [8] "512397" "623295" "589639" "550287" "550361" "596193" "464459"
## [15] "492777" "570411" "640464"
                          # 464459 492777 570411 640464
unique(qt1_01$Target) # 635665 490041 599956 589639 591682 616050 568093 632150 464459 533140 512397 550287 559657
##  [1] "635665" "490041" "599956" "589639" "591682" "616050" "568093"
##  [8] "632150" "464459" "533140" "512397" "550287" "559657" "492777"
## [15] "570411" "493044" "596193" "550361" "640464" "623295"
                            # 492777 570411 493044 596193 550361 640464 623295

colnames(qt1_01)
##  [1] "Source"          "eType"           "Target"         
##  [4] "Time"            "Weight"          "SourceLocation" 
##  [7] "TargetLocation"  "SourceLatitude"  "SourceLongitude"
## [10] "TargetLatitude"  "TargetLongitude"
# Analysis of the Demographic channel:
glimpse(qt1_5)
## Observations: 846
## Variables: 11
## $ Source          <chr> "608827", "552988", "608827", "608827", "60882...
## $ eType           <int> 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5...
## $ Target          <chr> "630626", "608827", "567195", "527449", "45938...
## $ Time            <int> 31536000, 31536000, 31536000, 31536000, 315360...
## $ Weight          <dbl> 21699.30, 143858.00, 15088.40, 456.71, 2378.60...
## $ SourceLocation  <int> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
## $ TargetLocation  <int> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
## $ SourceLatitude  <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
## $ SourceLongitude <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
## $ TargetLatitude  <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
## $ TargetLongitude <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
#unique(qt1_5)
unique(qt1_5$eType) # 5
## [1] 5
unique(qt1_5$SourceLocation) # NA
## [1] NA
unique(qt1_5$TargetLocation) # NA
## [1] NA
unique(qt1_5$SourceLatitude) # NA
## [1] NA
unique(qt1_5$SourceLongitude) # NA
## [1] NA
unique(qt1_5$TargetLatitude) # NA
## [1] NA
unique(qt1_5$TargetLongitude) # NA
## [1] NA
unique(qt1_5$Source)
##  [1] "608827" "552988" "589639" "510031" "530528" "635706" "490041"
##  [8] "554431" "620120" "599956" "566342" "548513" "599057" "568093"
## [15] "464459" "635665" "474199" "475130" "596193" "576641" "550361"
## [22] "463777" "654763" "529922" "599063" "622296" "512397" "493044"
## [29] "592414" "575704" "654981" "575859" "640464" "505722" "517273"
## [36] "492286" "636961" "570411" "623295" "492777" "629717" "502591"
## [43] "569820" "591682" "632150" "616050" "533140"
unique(qt1_5$Target)
##  [1] "630626" "608827" "567195" "527449" "459381" "595298" "466907"
##  [8] "589943" "537281" "580426" "595581" "616315" "642329" "503701"
## [15] "632961" "473173" "620120" "575030" "621924" "536346" "589639"
## [22] "520660" "577992" "571970" "644226" "530528" "523927" "635706"
## [29] "490041" "554431" "599956" "566342" "548513" "599057" "568093"
## [36] "464459" "640784" "635665" "474199" "475130" "596193" "576641"
## [43] "550361" "463777" "503218" "654763" "529922" "599063" "606730"
## [50] "622296" "512397" "493044" "592414" "575704" "654981" "575859"
## [57] "640464" "505722" "517273" "492286" "636961" "570411" "623295"
## [64] "492777" "629717" "502591" "569820" "591682" "632150" "616050"
## [71] "533140"
unique(qt1_5$Weight)
##   [1]  21699.30 143858.00  15088.40    456.71   2378.60   5362.15   1689.16
##   [8]   8444.03   2111.52    385.87   1006.36   6192.98   6393.29   2935.06
##  [15]    116.31   4951.15  19480.80  14153.40  12677.50  25079.40   9368.15
##  [22]   1840.81  12000.00 647030.00  35981.50   1570.79   1177.72   6259.14
##  [29]   4315.51  17326.80  59222.40   6812.65   7992.34  10936.90  11748.40
##  [36]    922.08   4393.27    657.25 256705.00  22255.40  20611.70   8433.51
##  [43]     42.39   1273.93  10454.00  22471.70   3256.84    626.25    709.74
##  [50]    323.75    803.27   5401.11    566.66   1055.24   1263.37   1860.01
##  [57]   1056.28    572.39   2654.76   1258.56   2025.14   3136.11  32074.00
##  [64]  23825.60 619963.00  19509.30    707.75   2812.20   1346.38   1827.44
##  [71]   8451.08    179.25   6537.83   7422.71   5502.61    419.71   1568.36
##  [78] 288399.00  12879.00   3877.78   3898.00   3164.62   9945.27   3425.74
##  [85]    190.90    944.51   2351.23   3472.76   2016.75   5981.19    541.23
##  [92]   2715.88   1124.28    755.36   1088.30   1277.89    546.79    902.70
##  [99]    989.20    309.48   8432.04   2533.31  25798.30   4869.66    477.21
## [106]    991.31   1022.79   1592.45   2292.69    575.81   2100.87    507.66
## [113]    864.50   3608.19  11532.20    109.57   2609.97   1916.13   8023.05
## [120]   4588.96  15128.20   2378.96   4527.75  11521.20  87411.80  14199.50
## [127]   1287.62   1200.80   5424.06   1734.92   4308.22    573.69   3138.12
## [134]   2612.14   4236.90   5658.37    801.56   3394.47   6039.55  33836.20
## [141]   4397.31   2836.39  11191.50    239.28    928.67   2976.70   1503.23
## [148]   1392.07   1673.49    729.47    695.41   2325.96   3830.14    409.84
## [155]    730.67    350.38    201.24   4154.76   1246.31   5458.02   3302.11
## [162]   1688.22   7279.05   8328.29   3345.40    706.38   2555.54   6392.63
## [169]   1499.50    479.26   4817.44     60.39   1464.26   1129.58   1057.83
## [176]    989.89  11194.70    937.43   1282.76   1584.35  26766.30   4545.13
## [183]     50.84   1671.82    151.14    607.33   2235.21    121.90   1013.67
## [190]   1123.79   2716.78   7222.34   2032.53    147.47   5174.10   2317.44
## [197]   3217.81  10786.00    423.63   1351.29   6929.54    462.80   2057.60
## [204]   5152.55    276.35   3047.35   4470.49   1230.07     55.90   1626.36
## [211]   2087.31   1770.99    453.32  51492.70   1167.72    534.04   1702.60
## [218]   2991.42   1601.52   3184.21   1845.19   1784.67   4296.71   3261.55
## [225]    763.63    699.42   1690.82   3442.81   6587.65   5937.72    197.19
## [232]   1388.78  30019.90   2739.08     39.34   1448.59   4378.48   3826.62
## [239]    377.01    698.17   1576.24   5382.42    896.83   4052.61   5472.26
## [246]  34041.90    461.46    556.31   7508.97    195.80    619.57    199.86
## [253]    900.45   1383.94    134.40    101.17    739.24    314.86    229.05
## [260]    134.02    826.39    500.51   3106.61   1288.30  10098.50    296.73
## [267]    464.59    760.17    750.34   2085.70     48.06    227.90    873.60
## [274]    606.11    923.51    691.64    233.20   1402.55     32.31    136.86
## [281]   1083.35    598.50   7055.78     25.88    498.56   3494.46    215.51
## [288]   5715.91     80.41    114.24    762.62   3200.76      5.50    505.63
## [295]    512.20   1413.95    740.74   5373.20   2326.88    101.93     57.70
## [302]    385.35   1277.17    607.00    564.31    276.28    496.73    480.73
## [309]    878.76   1617.76     62.22    349.80    532.92    367.71   2681.86
## [316]   1078.75  12586.90   2912.89    114.69    235.50   1135.49   2474.91
## [323]    489.54     94.05    382.99    820.04    201.32   1870.79    152.14
## [330]   1378.84    333.88     94.43   3691.55    626.00    583.52    763.66
## [337]    226.36   1823.50   7392.60    851.71    193.02    436.80   1409.48
## [344]    208.84    427.55   4864.11    474.25   1561.97    316.86    693.07
## [351]   1471.99   1690.67    205.66     73.59    522.83    168.12   2870.09
## [358]   4575.82    566.76   4412.63    999.02  22959.00   1941.65    399.58
## [365]    613.32   3795.32    511.93   2217.83   1069.28    169.61   1643.03
## [372]     50.58   1933.55    431.16     81.33    319.93    568.90   1537.07
## [379]   6042.72    561.90   1056.71  47106.50    889.15    233.11    388.16
## [386]   2032.07    512.78   3011.76    920.72    690.54    481.91   2047.56
## [393]   1647.79    220.36   3689.19    119.01   1072.89    390.31   1715.33
## [400]   7263.71   9216.46   1790.27   2267.03   1307.49     75.86   2061.29
## [407]  19798.90    960.36     54.66    414.66   2085.13   1092.76   1526.12
## [414]    554.65   1346.45   1443.58    581.21   3459.56   2836.08   2708.54
## [421]   3118.43    746.42   5301.05    942.41   3331.50  36123.40   2796.56
## [428]    170.12    667.40    567.63    554.54   2927.57    750.85   2215.35
## [435]   1981.13   2446.33    164.15    623.17    229.10    347.59   4579.47
## [442]    965.86     19.92   1119.13   6106.78    881.23   4200.84  32518.90
## [449]   4880.51    343.32    993.54   2840.81    711.50   1254.79    739.49
## [456]    732.21   3252.44   6308.05    321.43   1180.66     22.79   1984.33
## [463]    913.17   4962.24   4388.86  11068.60   2487.82   5087.50   1472.52
## [470]    822.40  18919.40   1684.01    377.60    224.81   1684.21    658.91
## [477]   1094.45     75.77    130.79   1412.76    125.63   2554.09   1702.58
## [484]     45.08   1858.42    774.25   7441.46   1167.94  49976.20   5063.82
## [491]    576.89   1265.29   3137.79   1107.68   5302.38   1441.09    720.36
## [498]   4573.48    483.10   2658.66   3429.01   1882.53   2522.31    243.81
## [505]    725.17   5471.99    596.72  31934.90    749.74   2391.69   4273.66
## [512]    196.03   9784.56   1557.66   1911.13    693.04   4613.15   2660.68
## [519]    849.79   3479.68   2255.94    304.79  10753.80   1787.56    558.05
## [526]   1805.45   1269.47    655.88   5306.54    244.20   2434.08    386.83
## [533]    986.55    586.73    499.85    620.87    732.43   2151.07   1267.83
## [540]   3304.77    477.89    132.10    766.88    366.20   1168.58   2274.47
## [547]    976.38    779.37   2474.64    183.40    440.95   1543.60   9070.65
## [554]   1296.75   1163.10   6292.61   3406.61    493.08   2318.11   5720.56
## [561]   1136.42    162.29   7905.27     20.21    899.28    129.52   1315.33
## [568]   4161.23    426.58    422.50   1259.00   1089.87   3780.69   4118.47
## [575]  34840.30   7190.11 900735.00  62750.40    238.75   1721.87   6060.91
## [582]   4593.29  20056.80   1137.66   3425.98  11587.20  14641.30  11493.80
## [589]  12163.60   8086.96   9231.82   9236.96  18476.70   3161.42 121149.00
## [596]    461.18   1589.03  18128.60   3709.53   6858.84   8669.64   1775.55
## [603]    286.56   8511.84   5037.65   3021.52   5355.92    436.23   2229.71
## [610]   1112.61  20241.90  14630.50   1370.28  12542.50  69256.80  14538.30
## [617]    883.83   1166.80   2904.37   1376.82    598.14   5422.26   5061.07
## [624]   7666.80    905.48   4242.92    260.88   1609.83    794.47  15251.00
## [631]  39657.70     72.49   1323.60   3939.83   5807.39   2846.66    884.99
## [638]   2423.74    375.30    587.83      0.46    450.03    274.65   3215.16
## [645]     76.17    917.55   5236.45   2976.51    559.30    410.44   3209.39
## [652]   2524.68  15868.40   5580.80    209.30   5688.59  76722.10  17179.00
## [659]    574.26   1991.54   2665.72    690.53   1689.51   1317.79   3426.73
## [666]   2200.13    578.66   4046.65    985.43  12330.70   5599.51   2276.97
## [673]    467.09  11546.50    699.55    182.71    216.96    785.52    656.77
## [680]   1949.02    325.56    691.26   1906.60    802.67   1189.79   1553.68
## [687]   1131.20   1099.51   2838.79   9732.82   1073.08    124.26    360.75
## [694]    611.56    128.47   1598.66    185.63    535.22    815.28   1619.79
## [701]    146.65    147.32   1461.98    947.58   6491.57   1518.45   4249.15
## [708]   1091.21  21204.90   2015.43     73.20    889.20   2575.65    312.96
## [715]   2726.24   1563.82    654.51    245.42   2484.21    192.93   1856.92
## [722]    281.98    478.91    843.46   4168.46    296.54   4144.78   1101.40
## [729]    525.02   4874.08  54333.10    536.87    768.82    382.45   4093.29
## [736]    631.99   1369.20   1399.54    266.52   2099.77   2810.98   5503.51
## [743]    218.21    814.80    488.63    669.18   9247.45   2572.76    273.24
## [750]   8464.39   1702.37 202871.00   2942.39     87.40    629.72   3574.60
## [757]    808.95    534.52   5383.92    647.27   3093.55   2682.75   2875.99
## [764]   1345.06   3718.44    604.29   1512.55     97.31  73919.00   7133.86
## [771]   6704.79   1502.74   5662.73    678.13    986.71  25608.40    218.03
## [778]    622.49   3245.92    946.77   1180.70    712.92   2053.41    220.80
## [785]   2019.74    943.81    599.59   1694.31    806.75   2644.97   6090.91
## [792]   4091.49    137.73   4811.33    489.09  28528.20    303.25    790.06
## [799]   1224.30    658.42   2231.39   1608.67    915.47   1996.20   1118.52
## [806]    822.59   1302.15   3720.79    803.32   6218.94    540.85    637.05
## [813]  43606.40   9865.87    142.08    510.26   3407.94    824.91   2521.46
## [820]   1136.81   4913.07   2707.57   1036.27    360.95    821.76   8076.13
## [827]   7832.08   1670.72   3150.22    235.04  14701.40    534.56     96.46
## [834]    279.66   1314.31    507.01    530.60    497.08    239.94   1131.24
## [841]   1741.49     85.16    290.73   1516.94    333.78
qt1_5 <- subset(qt1_5, select = -c(SourceLocation, TargetLocation, SourceLatitude, SourceLongitude, TargetLatitude, TargetLongitude)) # SOurce and Target Latitude and Longitude columns removed as all Null.
colnames(qt1_5)
## [1] "Source" "eType"  "Target" "Time"   "Weight"
range(qt1_5$Source) # 463777-654981
## [1] "463777" "654981"
range(qt1_5$Target) # 459381-654981
## [1] "459381" "654981"
range(qt1_5$Time) # 31536000-31536000
## [1] 31536000 31536000
income_cat_qt1 <- NULL
# Income Categories:
for (i in (qt1_5$Source)) {
  for (j in (cat$NodeID)) {                   # cat_list contains all the demographic nodeIDs (from the DemographicNodeExtraction Script)
    if(i == j){
      income_cat_qt1 <- append(income_cat_qt1,i)
    }
  }
}

print(income_cat_qt1) # income categories extracted
##  [1] "552988" "510031" "552988" "510031" "552988" "510031" "552988"
##  [8] "552988" "510031" "552988" "620120" "510031" "552988" "552988"
## [15] "510031" "552988" "620120" "510031" "552988" "620120" "552988"
## [22] "510031" "552988" "620120" "510031" "552988" "510031" "552988"
## [29] "620120" "510031" "552988" "552988" "552988" "552988" "510031"
## [36] "552988" "620120" "510031" "552988" "552988" "510031" "552988"
## [43] "552988" "552988" "552988" "552988" "620120" "510031" "552988"
## [50] "510031" "552988" "510031" "552988" "510031" "552988" "620120"
## [57] "510031" "552988" "510031" "552988" "552988" "552988" "620120"
## [64] "510031" "552988" "510031" "552988" "552988" "620120" "510031"
## [71] "552988" "510031" "552988" "510031" "552988" "552988" "510031"
## [78] "552988" "510031" "552988" "510031" "552988"
unique(income_cat_qt1) # 3
## [1] "552988" "510031" "620120"
qt1_5_sub1 <- subset(qt1_5, qt1_5$Source == income_cat_qt1) # Subset of data with only income categories
## Warning in qt1_5$Source == income_cat_qt1: longer object length is not a
## multiple of shorter object length
str(qt1_5_sub1)
## 'data.frame':    38 obs. of  5 variables:
##  $ Source: chr  "510031" "552988" "510031" "552988" ...
##  $ eType : int  5 5 5 5 5 5 5 5 5 5 ...
##  $ Target: chr  "589639" "530528" "635706" "635706" ...
##  $ Time  : int  31536000 31536000 31536000 31536000 31536000 31536000 31536000 31536000 31536000 31536000 ...
##  $ Weight: num  1841 22472 23826 619963 9945 ...
plot(qt1_5_sub1$Source, qt1_5_sub1$Weight) # Plot of Monetary income in each category

# Expense Categories:
expense_cat_qt1 <- 0
for (k in qt1_5$Target) {
  for(l in cat$NodeID){ 
    if(k==l){
      expense_cat_qt1 <- append(expense_cat_qt1, k)
    }
  }

}
print(expense_cat_qt1) # expense categories extracted
##   [1] "0"      "630626" "567195" "527449" "459381" "595298" "466907"
##   [8] "589943" "537281" "580426" "595581" "616315" "642329" "503701"
##  [15] "632961" "473173" "620120" "575030" "621924" "630626" "536346"
##  [22] "520660" "567195" "527449" "459381" "595298" "466907" "589943"
##  [29] "577992" "595581" "616315" "642329" "503701" "571970" "644226"
##  [36] "473173" "620120" "575030" "621924" "630626" "536346" "520660"
##  [43] "567195" "527449" "459381" "595298" "466907" "577992" "523927"
##  [50] "580426" "616315" "642329" "503701" "571970" "644226" "632961"
##  [57] "473173" "620120" "630626" "567195" "527449" "459381" "595298"
##  [64] "466907" "589943" "537281" "580426" "642329" "503701" "571970"
##  [71] "473173" "620120" "575030" "630626" "536346" "520660" "567195"
##  [78] "527449" "459381" "595298" "589943" "537281" "523927" "616315"
##  [85] "642329" "503701" "571970" "644226" "632961" "473173" "620120"
##  [92] "575030" "621924" "630626" "567195" "527449" "459381" "595298"
##  [99] "466907" "589943" "537281" "523927" "580426" "595581" "642329"
## [106] "503701" "571970" "473173" "575030" "621924" "630626" "536346"
## [113] "520660" "567195" "527449" "459381" "595298" "466907" "589943"
## [120] "577992" "537281" "523927" "642329" "503701" "644226" "473173"
## [127] "620120" "575030" "621924" "630626" "527449" "459381" "595298"
## [134] "466907" "589943" "577992" "537281" "523927" "616315" "642329"
## [141] "571970" "632961" "473173" "620120" "575030" "621924" "630626"
## [148] "536346" "520660" "567195" "527449" "459381" "595298" "589943"
## [155] "580426" "595581" "571970" "644226" "473173" "621924" "630626"
## [162] "536346" "520660" "567195" "527449" "459381" "595298" "466907"
## [169] "589943" "577992" "523927" "595581" "616315" "503701" "644226"
## [176] "632961" "473173" "621924" "527449" "459381" "595298" "466907"
## [183] "589943" "577992" "580426" "595581" "616315" "503701" "632961"
## [190] "473173" "620120" "621924" "567195" "527449" "459381" "595298"
## [197] "466907" "577992" "537281" "523927" "595581" "616315" "571970"
## [204] "632961" "473173" "575030" "621924" "640784" "567195" "527449"
## [211] "459381" "595298" "577992" "537281" "580426" "642329" "503701"
## [218] "632961" "473173" "620120" "575030" "621924" "567195" "527449"
## [225] "459381" "595298" "589943" "577992" "537281" "580426" "595581"
## [232] "642329" "571970" "473173" "575030" "527449" "459381" "595298"
## [239] "466907" "589943" "577992" "537281" "523927" "580426" "595581"
## [246] "616315" "642329" "503701" "571970" "632961" "473173" "620120"
## [253] "527449" "459381" "595298" "466907" "577992" "523927" "580426"
## [260] "642329" "503701" "571970" "632961" "473173" "620120" "575030"
## [267] "621924" "567195" "527449" "459381" "595298" "466907" "589943"
## [274] "537281" "523927" "580426" "595581" "503701" "571970" "473173"
## [281] "620120" "575030" "630626" "536346" "567195" "527449" "459381"
## [288] "595298" "589943" "537281" "523927" "580426" "595581" "642329"
## [295] "503701" "571970" "644226" "473173" "620120" "575030" "621924"
## [302] "630626" "536346" "520660" "567195" "527449" "459381" "595298"
## [309] "466907" "589943" "577992" "537281" "523927" "580426" "595581"
## [316] "616315" "503701" "644226" "632961" "473173" "575030" "621924"
## [323] "503218" "630626" "567195" "527449" "459381" "595298" "466907"
## [330] "589943" "537281" "580426" "595581" "642329" "503701" "632961"
## [337] "473173" "620120" "575030" "621924" "630626" "536346" "520660"
## [344] "567195" "527449" "459381" "595298" "466907" "589943" "577992"
## [351] "523927" "580426" "595581" "616315" "642329" "503701" "571970"
## [358] "644226" "632961" "473173" "620120" "575030" "621924" "630626"
## [365] "536346" "520660" "567195" "527449" "459381" "595298" "606730"
## [372] "589943" "577992" "523927" "616315" "642329" "503701" "644226"
## [379] "632961" "473173" "620120" "621924" "630626" "536346" "520660"
## [386] "567195" "527449" "459381" "595298" "466907" "589943" "577992"
## [393] "595581" "616315" "503701" "571970" "644226" "632961" "473173"
## [400] "620120" "575030" "621924" "640784" "630626" "536346" "520660"
## [407] "567195" "527449" "459381" "595298" "466907" "606730" "577992"
## [414] "537281" "523927" "595581" "616315" "642329" "571970" "644226"
## [421] "632961" "473173" "620120" "575030" "621924" "630626" "536346"
## [428] "520660" "567195" "527449" "459381" "595298" "466907" "537281"
## [435] "523927" "580426" "595581" "642329" "503701" "644226" "632961"
## [442] "473173" "620120" "575030" "621924" "567195" "527449" "459381"
## [449] "595298" "466907" "589943" "577992" "537281" "523927" "580426"
## [456] "595581" "616315" "642329" "503701" "571970" "473173" "527449"
## [463] "459381" "595298" "606730" "589943" "537281" "523927" "580426"
## [470] "595581" "503701" "632961" "473173" "620120" "567195" "527449"
## [477] "459381" "595298" "466907" "577992" "537281" "523927" "580426"
## [484] "595581" "503701" "571970" "632961" "473173" "620120" "567195"
## [491] "527449" "459381" "595298" "589943" "537281" "523927" "580426"
## [498] "595581" "503701" "473173" "620120" "575030" "621924" "567195"
## [505] "527449" "459381" "595298" "466907" "589943" "577992" "537281"
## [512] "523927" "580426" "595581" "616315" "571970" "632961" "473173"
## [519] "621924" "503218" "630626" "567195" "527449" "459381" "595298"
## [526] "466907" "589943" "537281" "580426" "595581" "616315" "642329"
## [533] "503701" "473173" "620120" "621924" "630626" "527449" "459381"
## [540] "595298" "466907" "589943" "577992" "523927" "580426" "595581"
## [547] "616315" "642329" "503701" "571970" "632961" "473173" "620120"
## [554] "575030" "621924" "630626" "567195" "527449" "459381" "595298"
## [561] "466907" "537281" "523927" "595581" "616315" "642329" "503701"
## [568] "571970" "632961" "473173" "620120" "575030" "621924" "503218"
## [575] "630626" "567195" "527449" "459381" "595298" "466907" "589943"
## [582] "577992" "537281" "523927" "580426" "595581" "642329" "503701"
## [589] "571970" "473173" "621924" "630626" "536346" "520660" "567195"
## [596] "527449" "459381" "595298" "466907" "577992" "580426" "595581"
## [603] "503701" "571970" "644226" "473173" "620120" "575030" "621924"
## [610] "567195" "527449" "459381" "595298" "466907" "589943" "577992"
## [617] "537281" "523927" "595581" "503701" "473173" "620120" "621924"
## [624] "630626" "567195" "527449" "459381" "595298" "466907" "589943"
## [631] "580426" "616315" "642329" "503701" "571970" "632961" "473173"
## [638] "575030" "621924" "630626" "567195" "527449" "459381" "595298"
## [645] "466907" "589943" "577992" "523927" "580426" "616315" "642329"
## [652] "503701" "632961" "473173" "620120" "575030" "621924" "630626"
## [659] "536346" "520660" "567195" "527449" "459381" "595298" "466907"
## [666] "577992" "537281" "523927" "595581" "616315" "503701" "571970"
## [673] "644226" "632961" "473173" "620120" "621924" "640784" "630626"
## [680] "567195" "527449" "459381" "595298" "466907" "606730" "589943"
## [687] "537281" "523927" "580426" "595581" "642329" "503701" "571970"
## [694] "632961" "473173" "620120" "575030" "621924" "640784" "630626"
## [701] "536346" "520660" "527449" "459381" "595298" "466907" "589943"
## [708] "537281" "523927" "580426" "595581" "616315" "642329" "644226"
## [715] "632961" "473173" "620120" "575030" "621924" "630626" "527449"
## [722] "459381" "595298" "466907" "589943" "523927" "580426" "595581"
## [729] "616315" "503701" "473173" "620120" "621924" "630626" "536346"
## [736] "567195" "527449" "459381" "595298" "466907" "589943" "523927"
## [743] "595581" "503701" "644226" "632961" "473173" "620120" "575030"
## [750] "621924" "630626" "567195" "527449" "459381" "595298" "466907"
## [757] "577992" "537281" "616315" "642329" "503701" "571970" "632961"
## [764] "473173" "620120"
unique(expense_cat_qt1) # 27
##  [1] "0"      "630626" "567195" "527449" "459381" "595298" "466907"
##  [8] "589943" "537281" "580426" "595581" "616315" "642329" "503701"
## [15] "632961" "473173" "620120" "575030" "621924" "536346" "520660"
## [22] "577992" "571970" "644226" "523927" "640784" "503218" "606730"
qt1_5_sub2 <- subset(qt1_5, qt1_5$Target == expense_cat_qt1) # Subset of data with only expense categories
## Warning in qt1_5$Target == expense_cat_qt1: longer object length is not a
## multiple of shorter object length
str(qt1_5_sub2)
## 'data.frame':    43 obs. of  5 variables:
##  $ Source: chr  "608827" "608827" "608827" "608827" ...
##  $ eType : int  5 5 5 5 5 5 5 5 5 5 ...
##  $ Target: chr  "567195" "527449" "459381" "595298" ...
##  $ Time  : int  31536000 31536000 31536000 31536000 31536000 31536000 31536000 31536000 31536000 31536000 ...
##  $ Weight: num  15088 457 2379 5362 1689 ...
plot(qt1_5_sub2$Target, qt1_5_sub2$Weight) # Plot of Monetary expenses in each category

hist(qt1_5$Weight)

unique(qt1_5$Weight)
##   [1]  21699.30 143858.00  15088.40    456.71   2378.60   5362.15   1689.16
##   [8]   8444.03   2111.52    385.87   1006.36   6192.98   6393.29   2935.06
##  [15]    116.31   4951.15  19480.80  14153.40  12677.50  25079.40   9368.15
##  [22]   1840.81  12000.00 647030.00  35981.50   1570.79   1177.72   6259.14
##  [29]   4315.51  17326.80  59222.40   6812.65   7992.34  10936.90  11748.40
##  [36]    922.08   4393.27    657.25 256705.00  22255.40  20611.70   8433.51
##  [43]     42.39   1273.93  10454.00  22471.70   3256.84    626.25    709.74
##  [50]    323.75    803.27   5401.11    566.66   1055.24   1263.37   1860.01
##  [57]   1056.28    572.39   2654.76   1258.56   2025.14   3136.11  32074.00
##  [64]  23825.60 619963.00  19509.30    707.75   2812.20   1346.38   1827.44
##  [71]   8451.08    179.25   6537.83   7422.71   5502.61    419.71   1568.36
##  [78] 288399.00  12879.00   3877.78   3898.00   3164.62   9945.27   3425.74
##  [85]    190.90    944.51   2351.23   3472.76   2016.75   5981.19    541.23
##  [92]   2715.88   1124.28    755.36   1088.30   1277.89    546.79    902.70
##  [99]    989.20    309.48   8432.04   2533.31  25798.30   4869.66    477.21
## [106]    991.31   1022.79   1592.45   2292.69    575.81   2100.87    507.66
## [113]    864.50   3608.19  11532.20    109.57   2609.97   1916.13   8023.05
## [120]   4588.96  15128.20   2378.96   4527.75  11521.20  87411.80  14199.50
## [127]   1287.62   1200.80   5424.06   1734.92   4308.22    573.69   3138.12
## [134]   2612.14   4236.90   5658.37    801.56   3394.47   6039.55  33836.20
## [141]   4397.31   2836.39  11191.50    239.28    928.67   2976.70   1503.23
## [148]   1392.07   1673.49    729.47    695.41   2325.96   3830.14    409.84
## [155]    730.67    350.38    201.24   4154.76   1246.31   5458.02   3302.11
## [162]   1688.22   7279.05   8328.29   3345.40    706.38   2555.54   6392.63
## [169]   1499.50    479.26   4817.44     60.39   1464.26   1129.58   1057.83
## [176]    989.89  11194.70    937.43   1282.76   1584.35  26766.30   4545.13
## [183]     50.84   1671.82    151.14    607.33   2235.21    121.90   1013.67
## [190]   1123.79   2716.78   7222.34   2032.53    147.47   5174.10   2317.44
## [197]   3217.81  10786.00    423.63   1351.29   6929.54    462.80   2057.60
## [204]   5152.55    276.35   3047.35   4470.49   1230.07     55.90   1626.36
## [211]   2087.31   1770.99    453.32  51492.70   1167.72    534.04   1702.60
## [218]   2991.42   1601.52   3184.21   1845.19   1784.67   4296.71   3261.55
## [225]    763.63    699.42   1690.82   3442.81   6587.65   5937.72    197.19
## [232]   1388.78  30019.90   2739.08     39.34   1448.59   4378.48   3826.62
## [239]    377.01    698.17   1576.24   5382.42    896.83   4052.61   5472.26
## [246]  34041.90    461.46    556.31   7508.97    195.80    619.57    199.86
## [253]    900.45   1383.94    134.40    101.17    739.24    314.86    229.05
## [260]    134.02    826.39    500.51   3106.61   1288.30  10098.50    296.73
## [267]    464.59    760.17    750.34   2085.70     48.06    227.90    873.60
## [274]    606.11    923.51    691.64    233.20   1402.55     32.31    136.86
## [281]   1083.35    598.50   7055.78     25.88    498.56   3494.46    215.51
## [288]   5715.91     80.41    114.24    762.62   3200.76      5.50    505.63
## [295]    512.20   1413.95    740.74   5373.20   2326.88    101.93     57.70
## [302]    385.35   1277.17    607.00    564.31    276.28    496.73    480.73
## [309]    878.76   1617.76     62.22    349.80    532.92    367.71   2681.86
## [316]   1078.75  12586.90   2912.89    114.69    235.50   1135.49   2474.91
## [323]    489.54     94.05    382.99    820.04    201.32   1870.79    152.14
## [330]   1378.84    333.88     94.43   3691.55    626.00    583.52    763.66
## [337]    226.36   1823.50   7392.60    851.71    193.02    436.80   1409.48
## [344]    208.84    427.55   4864.11    474.25   1561.97    316.86    693.07
## [351]   1471.99   1690.67    205.66     73.59    522.83    168.12   2870.09
## [358]   4575.82    566.76   4412.63    999.02  22959.00   1941.65    399.58
## [365]    613.32   3795.32    511.93   2217.83   1069.28    169.61   1643.03
## [372]     50.58   1933.55    431.16     81.33    319.93    568.90   1537.07
## [379]   6042.72    561.90   1056.71  47106.50    889.15    233.11    388.16
## [386]   2032.07    512.78   3011.76    920.72    690.54    481.91   2047.56
## [393]   1647.79    220.36   3689.19    119.01   1072.89    390.31   1715.33
## [400]   7263.71   9216.46   1790.27   2267.03   1307.49     75.86   2061.29
## [407]  19798.90    960.36     54.66    414.66   2085.13   1092.76   1526.12
## [414]    554.65   1346.45   1443.58    581.21   3459.56   2836.08   2708.54
## [421]   3118.43    746.42   5301.05    942.41   3331.50  36123.40   2796.56
## [428]    170.12    667.40    567.63    554.54   2927.57    750.85   2215.35
## [435]   1981.13   2446.33    164.15    623.17    229.10    347.59   4579.47
## [442]    965.86     19.92   1119.13   6106.78    881.23   4200.84  32518.90
## [449]   4880.51    343.32    993.54   2840.81    711.50   1254.79    739.49
## [456]    732.21   3252.44   6308.05    321.43   1180.66     22.79   1984.33
## [463]    913.17   4962.24   4388.86  11068.60   2487.82   5087.50   1472.52
## [470]    822.40  18919.40   1684.01    377.60    224.81   1684.21    658.91
## [477]   1094.45     75.77    130.79   1412.76    125.63   2554.09   1702.58
## [484]     45.08   1858.42    774.25   7441.46   1167.94  49976.20   5063.82
## [491]    576.89   1265.29   3137.79   1107.68   5302.38   1441.09    720.36
## [498]   4573.48    483.10   2658.66   3429.01   1882.53   2522.31    243.81
## [505]    725.17   5471.99    596.72  31934.90    749.74   2391.69   4273.66
## [512]    196.03   9784.56   1557.66   1911.13    693.04   4613.15   2660.68
## [519]    849.79   3479.68   2255.94    304.79  10753.80   1787.56    558.05
## [526]   1805.45   1269.47    655.88   5306.54    244.20   2434.08    386.83
## [533]    986.55    586.73    499.85    620.87    732.43   2151.07   1267.83
## [540]   3304.77    477.89    132.10    766.88    366.20   1168.58   2274.47
## [547]    976.38    779.37   2474.64    183.40    440.95   1543.60   9070.65
## [554]   1296.75   1163.10   6292.61   3406.61    493.08   2318.11   5720.56
## [561]   1136.42    162.29   7905.27     20.21    899.28    129.52   1315.33
## [568]   4161.23    426.58    422.50   1259.00   1089.87   3780.69   4118.47
## [575]  34840.30   7190.11 900735.00  62750.40    238.75   1721.87   6060.91
## [582]   4593.29  20056.80   1137.66   3425.98  11587.20  14641.30  11493.80
## [589]  12163.60   8086.96   9231.82   9236.96  18476.70   3161.42 121149.00
## [596]    461.18   1589.03  18128.60   3709.53   6858.84   8669.64   1775.55
## [603]    286.56   8511.84   5037.65   3021.52   5355.92    436.23   2229.71
## [610]   1112.61  20241.90  14630.50   1370.28  12542.50  69256.80  14538.30
## [617]    883.83   1166.80   2904.37   1376.82    598.14   5422.26   5061.07
## [624]   7666.80    905.48   4242.92    260.88   1609.83    794.47  15251.00
## [631]  39657.70     72.49   1323.60   3939.83   5807.39   2846.66    884.99
## [638]   2423.74    375.30    587.83      0.46    450.03    274.65   3215.16
## [645]     76.17    917.55   5236.45   2976.51    559.30    410.44   3209.39
## [652]   2524.68  15868.40   5580.80    209.30   5688.59  76722.10  17179.00
## [659]    574.26   1991.54   2665.72    690.53   1689.51   1317.79   3426.73
## [666]   2200.13    578.66   4046.65    985.43  12330.70   5599.51   2276.97
## [673]    467.09  11546.50    699.55    182.71    216.96    785.52    656.77
## [680]   1949.02    325.56    691.26   1906.60    802.67   1189.79   1553.68
## [687]   1131.20   1099.51   2838.79   9732.82   1073.08    124.26    360.75
## [694]    611.56    128.47   1598.66    185.63    535.22    815.28   1619.79
## [701]    146.65    147.32   1461.98    947.58   6491.57   1518.45   4249.15
## [708]   1091.21  21204.90   2015.43     73.20    889.20   2575.65    312.96
## [715]   2726.24   1563.82    654.51    245.42   2484.21    192.93   1856.92
## [722]    281.98    478.91    843.46   4168.46    296.54   4144.78   1101.40
## [729]    525.02   4874.08  54333.10    536.87    768.82    382.45   4093.29
## [736]    631.99   1369.20   1399.54    266.52   2099.77   2810.98   5503.51
## [743]    218.21    814.80    488.63    669.18   9247.45   2572.76    273.24
## [750]   8464.39   1702.37 202871.00   2942.39     87.40    629.72   3574.60
## [757]    808.95    534.52   5383.92    647.27   3093.55   2682.75   2875.99
## [764]   1345.06   3718.44    604.29   1512.55     97.31  73919.00   7133.86
## [771]   6704.79   1502.74   5662.73    678.13    986.71  25608.40    218.03
## [778]    622.49   3245.92    946.77   1180.70    712.92   2053.41    220.80
## [785]   2019.74    943.81    599.59   1694.31    806.75   2644.97   6090.91
## [792]   4091.49    137.73   4811.33    489.09  28528.20    303.25    790.06
## [799]   1224.30    658.42   2231.39   1608.67    915.47   1996.20   1118.52
## [806]    822.59   1302.15   3720.79    803.32   6218.94    540.85    637.05
## [813]  43606.40   9865.87    142.08    510.26   3407.94    824.91   2521.46
## [820]   1136.81   4913.07   2707.57   1036.27    360.95    821.76   8076.13
## [827]   7832.08   1670.72   3150.22    235.04  14701.40    534.56     96.46
## [834]    279.66   1314.31    507.01    530.60    497.08    239.94   1131.24
## [841]   1741.49     85.16    290.73   1516.94    333.78
range(qt1_5$Weight) #0.46-900735.00
## [1]      0.46 900735.00
# To-do : normalise the weights to better visualise in graph. Convert to csv maybe.

Graph 2 Analysis:

qt2 <- data.table::fread(here::here("data", "Q1-Graph2.csv"))
head(qt2)
##    Source eType Target       Time    Weight SourceLocation TargetLocation
## 1: 563211     4 564798 -732727926 0.0188679             NA             NA
## 2: 563211     4 627390 -496596726 0.2000000             NA             NA
## 3: 563211     4 561114 -277745526 0.2500000             NA             NA
## 4: 541017     4 601492  -64423926 0.1428570             NA             NA
## 5: 572413     1 629627    1296000 1.0000000              4              4
## 6: 572413     1 505965    1302571 1.0000000              4              4
##    SourceLatitude SourceLongitude TargetLatitude TargetLongitude
## 1:             NA              NA             NA              NA
## 2:             NA              NA             NA              NA
## 3:             NA              NA             NA              NA
## 4:             NA              NA             NA              NA
## 5:       -2.24962        -165.651       -1.16067        -162.983
## 6:       -2.24962        -165.651       -3.88606        -166.186
tail(qt2)
##    Source eType Target     Time  Weight SourceLocation TargetLocation
## 1: 527597     5 503701 31536000  761.27             NA             NA
## 2: 527597     5 644226 31536000  981.94             NA             NA
## 3: 527597     5 632961 31536000  207.22             NA             NA
## 4: 527597     5 473173 31536000  820.07             NA             NA
## 5: 527597     5 620120 31536000 1277.46             NA             NA
## 6: 527597     5 621924 31536000  273.83             NA             NA
##    SourceLatitude SourceLongitude TargetLatitude TargetLongitude
## 1:             NA              NA             NA              NA
## 2:             NA              NA             NA              NA
## 3:             NA              NA             NA              NA
## 4:             NA              NA             NA              NA
## 5:             NA              NA             NA              NA
## 6:             NA              NA             NA              NA
# Summarising the Data:
summary(qt2)
##      Source           eType           Target            Time           
##  Min.   :464459   Min.   :0.000   Min.   :459381   Min.   :-732727926  
##  1st Qu.:527597   1st Qu.:1.000   1st Qu.:515794   1st Qu.:  22734657  
##  Median :552988   Median :5.000   Median :575030   Median :  31536000  
##  Mean   :560521   Mean   :3.452   Mean   :562981   Mean   :  24176653  
##  3rd Qu.:602912   3rd Qu.:5.000   3rd Qu.:620120   3rd Qu.:  31536000  
##  Max.   :656156   Max.   :6.000   Max.   :657173   Max.   :  31536000  
##                                                                        
##      Weight          SourceLocation TargetLocation SourceLatitude   
##  Min.   :     0.02   Min.   :0.00   Min.   :1.00   Min.   :-29.452  
##  1st Qu.:     1.00   1st Qu.:2.00   1st Qu.:2.00   1st Qu.:-25.422  
##  Median :   216.69   Median :3.00   Median :3.00   Median : -3.886  
##  Mean   :  1207.35   Mean   :2.91   Mean   :2.93   Mean   :-12.048  
##  3rd Qu.:   754.66   3rd Qu.:4.00   3rd Qu.:4.00   3rd Qu.: -1.161  
##  Max.   :196567.00   Max.   :4.00   Max.   :4.00   Max.   : 33.000  
##                      NA's   :1099   NA's   :1099   NA's   :1099     
##  SourceLongitude   TargetLatitude    TargetLongitude   
##  Min.   :-166.19   Min.   :-29.452   Min.   :-168.472  
##  1st Qu.:-162.98   1st Qu.:-25.422   1st Qu.:-162.983  
##  Median :-111.68   Median :-20.657   Median :-111.678  
##  Mean   : -91.90   Mean   :-12.702   Mean   : -85.901  
##  3rd Qu.: -13.37   3rd Qu.: -1.161   3rd Qu.:  -9.462  
##  Max.   :  91.00   Max.   :  6.715   Max.   :  91.784  
##  NA's   :1099      NA's   :1099      NA's   :1099
nrow(qt2) #1300
## [1] 1300
ncol(qt2) #11
## [1] 11
qt2$Source <- as.character(qt2$Source)
qt2$Target <- as.character(qt2$Target)

# Differentiating between channels:
qt2_01 <- qt2 %>% filter(qt2$eType == 0 | qt2$eType == 1) # Communication Channel
nrow(qt2_01) # 435
## [1] 435
qt2_23 <- qt2 %>% filter(qt2$eType == 2 | qt2$eType == 3) # Procurement Channel
nrow(qt2_23) # 14
## [1] 14
qt2_4 <- qt2 %>% filter(qt2$eType == 4) # Co-authorship Channel
nrow(qt2_4) # 4
## [1] 4
qt2_5 <- qt2 %>% filter(qt2$eType == 5) # Demographic Channel
nrow(qt2_5) # 823
## [1] 823
qt2_6 <- qt2 %>% filter(qt2$eType == 6) # Travel Channel
nrow(qt2_6) # 24
## [1] 24
# Highest data for Demographic, Communication and Travel Channel.

# Analysis of the Communication channel:
glimpse(qt2_01)
## Observations: 435
## Variables: 11
## $ Source          <chr> "572413", "572413", "505965", "572413", "62962...
## $ eType           <int> 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1...
## $ Target          <chr> "629627", "505965", "629627", "505965", "51579...
## $ Time            <int> 1296000, 1302571, 1308663, 1316274, 1316615, 1...
## $ Weight          <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1...
## $ SourceLocation  <int> 4, 4, NA, 4, 4, NA, 4, 4, 4, 4, 4, NA, 4, NA, ...
## $ TargetLocation  <int> 4, 4, NA, 4, 4, NA, 4, 4, 4, 4, 4, NA, 4, NA, ...
## $ SourceLatitude  <dbl> -2.24962, -2.24962, NA, -2.24962, -1.16067, NA...
## $ SourceLongitude <dbl> -165.651, -165.651, NA, -165.651, -162.983, NA...
## $ TargetLatitude  <dbl> -1.16067, -3.88606, NA, -3.88606, 6.71518, NA,...
## $ TargetLongitude <dbl> -162.983, -166.186, NA, -166.186, -165.251, NA...
#unique(qt2_01)
unique(qt2_01$eType) # 0 1
## [1] 1 0
unique(qt2_01$SourceLocation) 
## [1]  4 NA  1  3  2
unique(qt2_01$TargetLocation) 
## [1]  4 NA  1  2  3
unique(qt2_01$SourceLatitude) 
##  [1]  -2.24962        NA  -1.16067   6.71518   5.62833 -29.45240 -26.66880
##  [8] -27.55500  -3.88606 -28.38010 -24.71710 -25.42200 -24.01270
unique(qt2_01$SourceLongitude) 
##  [1] -165.65100         NA -162.98300 -165.25100 -161.11300  -13.64910
##  [7]   -7.31949  -13.37300 -166.18600   -9.46184 -111.47400 -111.67800
## [13]   90.97340
unique(qt2_01$TargetLatitude) 
##  [1]  -1.160670  -3.886060         NA   6.715180 -27.335300 -29.452400
##  [7]   2.747850 -27.555000   5.628330   0.486228 -26.668800 -24.012700
## [13] -24.717100 -25.422000 -20.656500 -28.380100
unique(qt2_01$TargetLongitude) 
##  [1] -162.98300 -166.18600         NA -165.25100  -18.22270  -13.64910
##  [7] -162.27500  -13.37300 -161.11300 -168.47200   -7.31949   90.97340
## [13] -111.47400 -111.67800   91.78410   -9.46184
unique(qt2_01$Source) 
##  [1] "572413" "505965" "629627" "515794" "541017" "585212" "599441"
##  [8] "582851" "527597" "563211" "534034" "644830" "488928" "602912"
## [15] "477138" "544615" "534449" "639051"
unique(qt2_01$Target) 
##  [1] "629627" "505965" "515794" "563211" "541017" "599441" "527597"
##  [8] "585212" "534034" "582851" "488928" "644830" "534449" "477138"
## [15] "639051" "544615" "602912"
colnames(qt2_01)
##  [1] "Source"          "eType"           "Target"         
##  [4] "Time"            "Weight"          "SourceLocation" 
##  [7] "TargetLocation"  "SourceLatitude"  "SourceLongitude"
## [10] "TargetLatitude"  "TargetLongitude"
# Analysis of the Demographic channel:
glimpse(qt2_5)
## Observations: 823
## Variables: 11
## $ Source          <chr> "604021", "604021", "510031", "604021", "55298...
## $ eType           <int> 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5...
## $ Target          <chr> "630626", "536346", "604021", "520660", "60402...
## $ Time            <int> 31536000, 31536000, 31536000, 31536000, 315360...
## $ Weight          <dbl> 2258.44, 561.50, 113.92, 881.17, 7756.23, 134....
## $ SourceLocation  <int> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
## $ TargetLocation  <int> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
## $ SourceLatitude  <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
## $ SourceLongitude <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
## $ TargetLatitude  <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
## $ TargetLongitude <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
#unique(qt2_5)
unique(qt2_5$eType) # 5
## [1] 5
unique(qt2_5$SourceLocation) # NA
## [1] NA
unique(qt2_5$TargetLocation) # NA
## [1] NA
unique(qt2_5$SourceLatitude) # NA
## [1] NA
unique(qt2_5$SourceLongitude) # NA
## [1] NA
unique(qt2_5$TargetLatitude) # NA
## [1] NA
unique(qt2_5$TargetLongitude) # NA
## [1] NA
unique(qt2_5$Source)
##  [1] "604021" "510031" "552988" "533094" "606043" "595057" "634181"
##  [8] "548320" "505965" "572413" "515794" "563584" "629627" "534034"
## [15] "599441" "585212" "536953" "620120" "515799" "656156" "552439"
## [22] "546478" "488928" "602912" "533024" "499312" "464563" "546626"
## [29] "544615" "533141" "471663" "501047" "534449" "472522" "477138"
## [36] "475811" "590265" "653390" "573870" "645210" "639051" "582851"
## [43] "541017" "563211" "527597"
unique(qt2_5$Target)
##  [1] "630626" "536346" "604021" "520660" "527449" "459381" "595298"
##  [8] "466907" "577992" "580426" "595581" "616315" "503701" "571970"
## [15] "644226" "632961" "473173" "620120" "575030" "621924" "640784"
## [22] "533094" "567195" "537281" "523927" "642329" "606043" "589943"
## [29] "503218" "595057" "634181" "548320" "606730" "505965" "572413"
## [36] "515794" "563584" "629627" "534034" "599441" "585212" "536953"
## [43] "515799" "656156" "552439" "546478" "488928" "602912" "533024"
## [50] "499312" "464563" "546626" "544615" "533141" "471663" "501047"
## [57] "534449" "472522" "477138" "475811" "590265" "653390" "573870"
## [64] "645210" "639051" "582851" "541017" "563211" "527597"
unique(qt2_5$Weight)
##   [1]   2258.44    561.50    113.92    881.17   7756.23    134.84    193.22
##   [8]    355.82    209.22     31.35    132.22    421.43    234.74    176.53
##  [15]     84.22    766.83     92.79   1234.60    473.95   1236.75    658.78
##  [22]    318.41   3402.76    285.79     26.94   2267.78  25708.90   1613.63
##  [29]    370.94    284.32    782.50    242.12   1395.87    497.09   1242.83
##  [36]   1332.94    148.27   2402.81     78.91    924.08    110.68   1348.11
##  [43]   5654.70   2361.75    499.47     22.11   1829.16  17608.30    373.74
##  [50]     52.30    288.20    520.41    412.72   1457.54    804.23    993.32
##  [57]    639.26    260.21     76.04    210.77    112.26   1067.92   2296.04
##  [64]   6003.36    206.77   1361.75    167.12   5705.36     97.02     99.71
##  [71]    337.97    419.67    272.56    561.93     28.62    273.79    913.80
##  [78]    129.16    855.02    863.35   4289.16    350.13   2609.07    800.36
##  [85]   2233.87  15174.50    184.39    267.63    299.54    469.30    729.69
##  [92]   1370.33    912.34     65.04     32.69    354.00   1164.48     47.31
##  [99]    811.15    402.65    228.04   3565.20   2201.95    479.23   1270.54
## [106]    477.22    601.85    333.79  13557.00    878.46     64.15    340.62
## [113]   1531.39    500.35    448.03    357.11    791.93     13.93    520.35
## [120]    292.58    488.52    139.89    156.49    115.48   1123.42   1071.33
## [127]   3982.11    575.08   3348.11    271.34   1221.26   9945.54   3171.42
## [134]     79.82    227.65     82.96    322.05    489.12    572.58    515.71
## [141]    141.30     78.42    874.89     61.62    881.15    126.48   1141.88
## [148]   1428.67    647.87     88.82   1983.14    428.32    390.65  12652.90
## [155]   1743.69     73.26    295.58    754.28    187.96    187.52    447.60
## [162]    426.93      7.71    228.08    416.46    135.67    252.47     98.62
## [169]   2155.42     92.26   1596.67    584.60    153.68    460.23   1258.39
## [176]    135.71     81.80    223.74    891.28    458.25    117.13    658.22
## [183]    216.58    270.56    262.17      8.05    180.64    160.57     29.94
## [190]    377.60    146.35    347.88   2108.03    699.98   1691.94  11708.60
## [197]    233.94    551.66    483.37     88.39    693.99    668.48    489.58
## [204]    360.49    637.90    544.88    429.92     10.67    228.24    795.47
## [211]    939.88    319.50    336.04   6596.71    698.93    208.98    331.29
## [218]    701.57    554.90     40.21    485.15     79.87     54.06    372.04
## [225]   1001.63     41.97    854.79    822.54   1576.90    324.44   6909.84
## [232]     98.42     98.45    217.43    923.82    331.89    813.98      7.09
## [239]     24.66    243.16    196.86    519.34     37.46    159.21    359.29
## [246]    383.24    543.76    820.43     61.38     20.01    173.66    876.96
## [253]      0.17    149.80     41.42    440.57     63.91     68.27    277.77
## [260]    305.08     19.66     38.91    166.02    465.15    107.62   7023.93
## [267]    313.91     91.47    213.36   1168.03    237.14    449.99    556.72
## [274]     23.93    470.65    512.49    203.52    217.05     53.70    196.97
## [281]    116.19    233.26   6721.34    457.96    100.10    972.12   1530.76
## [288]    140.95   1330.24   1151.36    129.36    730.47     49.27    404.72
## [295]    684.01   1382.90    423.04   1534.03    617.00   1970.27   5150.48
## [302]    820.48    129.81    544.86    446.02    349.45   1011.71    683.75
## [309]     32.88    683.83   2272.00    144.34    475.94    688.32   3746.87
## [316]  13710.20   1205.77     20.87    543.68    719.01    335.87   1291.50
## [323]    398.58    362.16    412.75     70.98    557.16    879.41    369.95
## [330]    768.46     17.64    435.05    315.55   1089.36   4849.31    654.53
## [337]    244.14  13256.90    862.40    241.27    264.21   1949.10    407.88
## [344]   1173.18    485.44    212.58    365.46    738.10    603.48    433.68
## [351]   1827.65    384.62    229.16    742.59     35.23   4391.67    652.46
## [358]   8367.13   1323.35     47.57     71.09    634.80    318.20   1477.07
## [365]    456.72    494.24     37.01   1607.20     13.42    234.60    960.31
## [372]   1156.32   9595.78    600.97    618.86   7091.58   1106.18   2655.89
## [379]  20518.60   4060.69     77.62    355.15   1888.31    320.76    773.91
## [386]      6.50     25.88   1681.76    532.08    208.72   1713.46   1199.93
## [393]    456.15    226.36    164.14   1944.15    748.17   1941.85    744.35
## [400]   2191.45  18351.20    943.00     63.04    401.38   1754.04    279.50
## [407]   4242.50    519.27    428.19    729.65    352.81   1079.16      9.53
## [414]    543.70    272.54   1776.52    282.64   4800.15   2270.29  34513.10
## [421]   3896.34    122.51    748.85   1087.88    636.80   1271.14    838.17
## [428]   3030.47    629.02    894.90   1483.20   2764.54    622.46   1598.44
## [435]   2385.08    221.07   1421.09   3749.53   1044.11    691.62   1127.74
## [442]  19434.50    303.66    611.34   1652.08    596.25    498.96    210.09
## [449]    848.71    722.75    644.66   1661.06    103.71   1801.64    123.72
## [456]    206.09   2609.85   1313.85     17.46   6057.31    107.87   2362.89
## [463]  40893.30   3770.63    241.36    499.73   1287.29    275.05    832.72
## [470]    824.99   2432.58    419.41   2302.42   1479.93    498.09   2106.71
## [477]      5.50    663.04    328.49    171.99   5338.67   5816.30   1513.56
## [484]  13128.40   1910.13    422.90    653.41    619.61    224.34    843.58
## [491]    459.16    296.40    431.55    507.64    538.93    316.14   1389.58
## [498]   1430.00   1403.88  14125.60   1209.50    185.85    138.81   4226.85
## [505]    292.64    497.49    441.68   1859.23    171.51    909.43    944.79
## [512]     29.26   2483.79    133.20    458.40    964.83    687.54     16.56
## [519]    213.04  12388.00    212.89    179.11    886.18    558.24   1199.16
## [526]    203.90     85.73   1197.33    757.71    292.42   2727.48    105.77
## [533]    362.27   2263.32   1499.45   2176.30    791.50  14177.30     68.49
## [540]    125.72   2279.98    235.75   1158.45    382.24    372.92    589.65
## [547]    403.43   2341.83    401.77   1616.43   1252.03     67.22    194.61
## [554]    629.48  10817.20    929.07    137.84    591.71   2671.77    485.28
## [561]    251.56   2970.58    282.30    826.02    737.78    269.63   2476.78
## [568]     26.77   1144.80   1016.19   4418.43   1185.68   2249.89    216.81
## [575]    813.87   3004.24    322.32    665.70     10.19    605.53      7.18
## [582]   2109.64    198.29    285.36    395.95   2352.91   5748.55    518.51
## [589]    149.26     72.22    751.42    622.66    627.20    132.09    436.19
## [596]    233.23   2178.34   1014.78   3103.23    222.45    152.82   1699.98
## [603]    693.40   1990.33   5714.39    245.84    323.70    298.45    348.78
## [610]    185.98   1048.98    194.30    420.67    309.72    957.56    777.37
## [617]     39.66    330.35    258.62    277.92   4111.40    119.59    434.28
## [624]    316.24      5.48    228.28    265.86   1201.20    102.41    723.10
## [631]     39.47    116.78    121.89    966.10   2365.02   8856.87    384.70
## [638]    279.16    856.28    643.53    494.53    276.79    438.82    489.27
## [645]   1117.11    155.39    487.37    357.90    411.14    141.13   1069.34
## [652]    752.56  12740.80   1592.10    724.17  10042.30    127.56    358.62
## [659]    431.14   1064.83     99.86    509.25    890.84    336.03    548.16
## [666]    948.67    415.63    331.71    113.71    251.39   1492.32    164.80
## [673]   1763.26     31.08   2228.22    356.61   3019.34    241.38    620.70
## [680]    414.28    257.91   1416.17     20.72    639.76     99.74    481.03
## [687]    435.73    184.64    746.46    274.71    415.50    351.06   1170.20
## [694]   4792.16    437.54  29973.60    278.77    713.63   1592.06    550.46
## [701]    157.68    418.13   1223.88     37.94    311.95   2090.93    408.57
## [708]   1135.98   1024.90    427.59   1480.23   6687.72   9218.86   8012.80
## [715] 196567.00  13536.00    131.53    504.52    363.71    628.37   3250.02
## [722]   3604.06     74.73   1281.50   4821.65   3029.73   1839.38   2175.30
## [729]  47680.00  11164.10    339.98   5865.03   1010.50   1548.47  18671.50
## [736]   2519.64     59.25    592.99    918.16    274.50   1765.12     26.02
## [743]    687.27    674.77   1318.01    650.69   1331.52    127.16    629.85
## [750]    945.16   4056.11   3336.95    823.05   3583.08     21.36    289.46
## [757]   2432.00  28827.50   6094.45    276.94    635.57   3947.64    820.82
## [764]    729.14   3067.24    195.49   1935.69   3866.28   3532.11    484.08
## [771]    180.92   1529.05    431.03    642.78   3517.98   8084.37   1292.87
## [778]   4267.76    464.86   2700.90  33865.00   5301.34     96.34    325.71
## [785]   2348.19    801.11   1121.43   2947.72    855.53   2739.30    908.48
## [792]    820.14   1218.25   2401.99    286.60    212.56   2758.33   6505.41
## [799]    855.88    440.68   3860.15    401.15   1609.38  18210.20   2346.63
## [806]    202.12    680.91    548.87    755.80    273.80    385.10    406.02
## [813]    167.01    352.52    412.29    761.27    981.94    207.22    820.07
## [820]   1277.46    273.83
qt2_5 <- subset(qt2_5, select = -c(SourceLocation, TargetLocation, SourceLatitude, SourceLongitude, TargetLatitude, TargetLongitude)) # SOurce and Target Latitude and Longitude columns removed as all Null.
colnames(qt2_5)
## [1] "Source" "eType"  "Target" "Time"   "Weight"
any(qt2_5$Source) == any(qt2_5$Target) # True
## Warning in any(qt2_5$Source): coercing argument of type 'character' to
## logical
## Warning in any(qt2_5$Target): coercing argument of type 'character' to
## logical
## [1] NA
range(qt2_5$Source) # 464563-656156
## [1] "464563" "656156"
range(qt2_5$Target) # 459381-656156
## [1] "459381" "656156"
range(qt2_5$Time) # 31536000-31536000
## [1] 31536000 31536000
income_cat_qt2 <- NULL
# Income Categories:
for (i in (qt2_5$Source)) {
  for (j in (cat$NodeID)) {                   # cat_list contains all the demographic nodeIDs (from the DemographicNodeExtraction Script)
    if(i == j){
      income_cat_qt2 <- append(income_cat_qt2,i)
    }
  }
}

print(income_cat_qt2) # income categories extracted
##  [1] "510031" "552988" "510031" "552988" "510031" "552988" "510031"
##  [8] "552988" "552988" "510031" "552988" "552988" "552988" "510031"
## [15] "552988" "552988" "510031" "552988" "552988" "552988" "552988"
## [22] "552988" "620120" "552988" "552988" "510031" "552988" "510031"
## [29] "552988" "620120" "552988" "620120" "552988" "510031" "552988"
## [36] "510031" "552988" "552988" "552988" "552988" "510031" "552988"
## [43] "620120" "510031" "552988" "552988" "620120" "552988" "552988"
## [50] "620120" "552988" "620120" "510031" "552988" "620120" "552988"
## [57] "620120" "510031" "552988" "510031" "552988" "510031" "552988"
## [64] "510031" "552988" "552988" "510031" "552988" "510031" "552988"
## [71] "552988"
unique(income_cat_qt2) # 3
## [1] "510031" "552988" "620120"
qt2_5_sub1 <- subset(qt2_5, qt2_5$Source == income_cat_qt2) # Subset of data with only income categories
## Warning in qt2_5$Source == income_cat_qt2: longer object length is not a
## multiple of shorter object length
str(qt2_5_sub1)
## 'data.frame':    38 obs. of  5 variables:
##  $ Source: chr  "510031" "552988" "552988" "510031" ...
##  $ eType : int  5 5 5 5 5 5 5 5 5 5 ...
##  $ Target: chr  "604021" "533094" "606043" "595057" ...
##  $ Time  : int  31536000 31536000 31536000 31536000 31536000 31536000 31536000 31536000 31536000 31536000 ...
##  $ Weight: num  114 25709 17608 167 5705 ...
plot(qt2_5_sub1$Source, qt2_5_sub1$Weight) # Plot of Monetary income in each category

# Expense Categories:
expense_cat_qt2 <- NULL
for (k in qt2_5$Target) {
  for(l in cat$NodeID){ 
    if(k==l){
      expense_cat_qt2 <- append(expense_cat_qt2, k)
    }
  }
  
}
print(expense_cat_qt2) # expense categories extracted
##   [1] "630626" "536346" "520660" "527449" "459381" "595298" "466907"
##   [8] "577992" "580426" "595581" "616315" "503701" "571970" "644226"
##  [15] "632961" "473173" "620120" "575030" "621924" "640784" "630626"
##  [22] "536346" "520660" "567195" "527449" "459381" "595298" "466907"
##  [29] "577992" "537281" "523927" "616315" "642329" "503701" "571970"
##  [36] "644226" "632961" "473173" "620120" "630626" "536346" "520660"
##  [43] "567195" "527449" "459381" "595298" "466907" "589943" "577992"
##  [50] "523927" "595581" "616315" "571970" "644226" "632961" "473173"
##  [57] "620120" "575030" "503218" "630626" "567195" "527449" "459381"
##  [64] "595298" "466907" "589943" "580426" "642329" "503701" "632961"
##  [71] "473173" "620120" "575030" "621924" "630626" "536346" "520660"
##  [78] "527449" "459381" "595298" "466907" "589943" "577992" "523927"
##  [85] "580426" "595581" "642329" "503701" "571970" "644226" "632961"
##  [92] "473173" "620120" "575030" "503218" "630626" "536346" "520660"
##  [99] "567195" "527449" "459381" "595298" "466907" "606730" "537281"
## [106] "523927" "595581" "616315" "642329" "503701" "571970" "644226"
## [113] "632961" "473173" "620120" "575030" "621924" "630626" "536346"
## [120] "520660" "567195" "527449" "459381" "595298" "466907" "577992"
## [127] "537281" "523927" "580426" "595581" "503701" "571970" "644226"
## [134] "473173" "620120" "575030" "621924" "640784" "630626" "536346"
## [141] "520660" "567195" "527449" "459381" "595298" "466907" "580426"
## [148] "595581" "616315" "642329" "503701" "644226" "632961" "473173"
## [155] "620120" "575030" "621924" "630626" "536346" "520660" "567195"
## [162] "527449" "459381" "595298" "589943" "577992" "523927" "580426"
## [169] "595581" "642329" "571970" "644226" "632961" "473173" "620120"
## [176] "621924" "503218" "630626" "536346" "520660" "527449" "459381"
## [183] "595298" "466907" "589943" "577992" "537281" "523927" "616315"
## [190] "642329" "503701" "571970" "644226" "473173" "620120" "575030"
## [197] "567195" "527449" "459381" "595298" "589943" "537281" "523927"
## [204] "580426" "595581" "642329" "503701" "571970" "473173" "620120"
## [211] "575030" "503218" "567195" "527449" "459381" "595298" "466907"
## [218] "589943" "523927" "580426" "595581" "642329" "503701" "571970"
## [225] "632961" "473173" "620120" "621924" "567195" "527449" "459381"
## [232] "595298" "466907" "589943" "537281" "523927" "580426" "595581"
## [239] "616315" "503701" "571970" "632961" "473173" "620120" "621924"
## [246] "567195" "527449" "459381" "595298" "466907" "589943" "577992"
## [253] "580426" "595581" "616315" "642329" "503701" "632961" "473173"
## [260] "620120" "621924" "567195" "527449" "459381" "595298" "466907"
## [267] "589943" "577992" "537281" "523927" "580426" "595581" "616315"
## [274] "503701" "632961" "473173" "575030" "567195" "527449" "459381"
## [281] "595298" "466907" "589943" "523927" "580426" "616315" "503701"
## [288] "632961" "473173" "620120" "621924" "567195" "527449" "459381"
## [295] "595298" "466907" "589943" "577992" "537281" "523927" "580426"
## [302] "595581" "616315" "642329" "503701" "571970" "632961" "473173"
## [309] "620120" "575030" "630626" "567195" "527449" "459381" "595298"
## [316] "466907" "589943" "577992" "537281" "523927" "595581" "616315"
## [323] "642329" "503701" "632961" "473173" "620120" "621924" "630626"
## [330] "567195" "527449" "459381" "595298" "466907" "589943" "523927"
## [337] "616315" "642329" "503701" "571970" "632961" "473173" "575030"
## [344] "621924" "503218" "630626" "536346" "520660" "567195" "527449"
## [351] "459381" "595298" "466907" "606730" "577992" "537281" "523927"
## [358] "580426" "616315" "503701" "644226" "632961" "473173" "575030"
## [365] "621924" "630626" "536346" "520660" "567195" "527449" "459381"
## [372] "595298" "466907" "589943" "537281" "523927" "616315" "642329"
## [379] "503701" "571970" "644226" "473173" "620120" "640784" "630626"
## [386] "567195" "527449" "459381" "595298" "466907" "577992" "537281"
## [393] "523927" "580426" "595581" "642329" "503701" "632961" "473173"
## [400] "620120" "575030" "621924" "630626" "536346" "520660" "527449"
## [407] "459381" "595298" "466907" "577992" "537281" "523927" "616315"
## [414] "642329" "503701" "571970" "644226" "632961" "473173" "620120"
## [421] "575030" "621924" "630626" "536346" "520660" "567195" "527449"
## [428] "459381" "595298" "466907" "606730" "589943" "577992" "537281"
## [435] "523927" "595581" "642329" "503701" "571970" "644226" "632961"
## [442] "473173" "620120" "575030" "621924" "567195" "527449" "459381"
## [449] "595298" "466907" "589943" "577992" "580426" "595581" "642329"
## [456] "503701" "632961" "473173" "620120" "621924" "567195" "527449"
## [463] "459381" "595298" "466907" "589943" "537281" "523927" "580426"
## [470] "595581" "616315" "642329" "503701" "571970" "632961" "473173"
## [477] "620120" "621924" "527449" "459381" "595298" "466907" "589943"
## [484] "537281" "580426" "595581" "616315" "642329" "503701" "571970"
## [491] "632961" "473173" "621924" "567195" "527449" "459381" "595298"
## [498] "466907" "589943" "577992" "595581" "616315" "642329" "503701"
## [505] "632961" "473173" "620120" "575030" "621924" "503218" "567195"
## [512] "527449" "459381" "595298" "466907" "589943" "523927" "580426"
## [519] "595581" "616315" "642329" "503701" "632961" "473173" "575030"
## [526] "630626" "527449" "459381" "595298" "466907" "589943" "537281"
## [533] "595581" "616315" "503701" "473173" "620120" "575030" "630626"
## [540] "567195" "527449" "459381" "595298" "466907" "606730" "589943"
## [547] "580426" "595581" "616315" "642329" "503701" "571970" "473173"
## [554] "575030" "621924" "567195" "527449" "459381" "595298" "466907"
## [561] "577992" "537281" "523927" "580426" "595581" "616315" "571970"
## [568] "473173" "527449" "459381" "595298" "466907" "589943" "537281"
## [575] "523927" "595581" "616315" "642329" "632961" "473173" "575030"
## [582] "567195" "527449" "459381" "595298" "466907" "589943" "577992"
## [589] "537281" "523927" "580426" "616315" "642329" "503701" "632961"
## [596] "473173" "575030" "621924" "567195" "527449" "459381" "595298"
## [603] "466907" "606730" "589943" "577992" "537281" "523927" "580426"
## [610] "595581" "616315" "642329" "503701" "571970" "473173" "620120"
## [617] "621924" "527449" "459381" "595298" "466907" "577992" "537281"
## [624] "523927" "580426" "595581" "616315" "642329" "503701" "632961"
## [631] "473173" "620120" "575030" "630626" "527449" "459381" "595298"
## [638] "466907" "589943" "577992" "537281" "523927" "580426" "595581"
## [645] "616315" "642329" "503701" "632961" "473173" "620120" "575030"
## [652] "630626" "567195" "527449" "459381" "595298" "466907" "589943"
## [659] "577992" "537281" "580426" "595581" "642329" "503701" "473173"
## [666] "620120" "575030" "640784" "630626" "536346" "520660" "567195"
## [673] "527449" "459381" "595298" "466907" "589943" "577992" "537281"
## [680] "580426" "595581" "642329" "503701" "644226" "632961" "473173"
## [687] "620120" "575030" "503218" "630626" "536346" "520660" "567195"
## [694] "527449" "459381" "595298" "466907" "606730" "589943" "577992"
## [701] "523927" "595581" "616315" "642329" "571970" "644226" "632961"
## [708] "473173" "620120" "575030" "621924" "630626" "536346" "567195"
## [715] "527449" "459381" "595298" "466907" "589943" "577992" "537281"
## [722] "523927" "580426" "595581" "642329" "503701" "644226" "632961"
## [729] "473173" "620120" "575030" "640784" "630626" "536346" "520660"
## [736] "567195" "527449" "459381" "595298" "466907" "577992" "537281"
## [743] "523927" "580426" "595581" "642329" "503701" "644226" "632961"
## [750] "473173" "620120" "621924"
unique(expense_cat_qt2) # 27
##  [1] "630626" "536346" "520660" "527449" "459381" "595298" "466907"
##  [8] "577992" "580426" "595581" "616315" "503701" "571970" "644226"
## [15] "632961" "473173" "620120" "575030" "621924" "640784" "567195"
## [22] "537281" "523927" "642329" "589943" "503218" "606730"
qt2_5_sub2 <- subset(qt2_5, qt2_5$Target == expense_cat_qt2) # Subset of data with only expense categories
## Warning in qt2_5$Target == expense_cat_qt2: longer object length is not a
## multiple of shorter object length
str(qt2_5_sub2)
## 'data.frame':    10 obs. of  5 variables:
##  $ Source: chr  "604021" "604021" "563584" "563584" ...
##  $ eType : int  5 5 5 5 5 5 5 5 5 5
##  $ Target: chr  "630626" "536346" "589943" "642329" ...
##  $ Time  : int  31536000 31536000 31536000 31536000 31536000 31536000 31536000 31536000 31536000 31536000
##  $ Weight: num  2258 562 694 545 430 ...
plot(qt2_5_sub2$Target, qt2_5_sub2$Weight) # Plot of Monetary expenses in each category

hist(qt2_5$Weight)

unique(qt2_5$Weight)
##   [1]   2258.44    561.50    113.92    881.17   7756.23    134.84    193.22
##   [8]    355.82    209.22     31.35    132.22    421.43    234.74    176.53
##  [15]     84.22    766.83     92.79   1234.60    473.95   1236.75    658.78
##  [22]    318.41   3402.76    285.79     26.94   2267.78  25708.90   1613.63
##  [29]    370.94    284.32    782.50    242.12   1395.87    497.09   1242.83
##  [36]   1332.94    148.27   2402.81     78.91    924.08    110.68   1348.11
##  [43]   5654.70   2361.75    499.47     22.11   1829.16  17608.30    373.74
##  [50]     52.30    288.20    520.41    412.72   1457.54    804.23    993.32
##  [57]    639.26    260.21     76.04    210.77    112.26   1067.92   2296.04
##  [64]   6003.36    206.77   1361.75    167.12   5705.36     97.02     99.71
##  [71]    337.97    419.67    272.56    561.93     28.62    273.79    913.80
##  [78]    129.16    855.02    863.35   4289.16    350.13   2609.07    800.36
##  [85]   2233.87  15174.50    184.39    267.63    299.54    469.30    729.69
##  [92]   1370.33    912.34     65.04     32.69    354.00   1164.48     47.31
##  [99]    811.15    402.65    228.04   3565.20   2201.95    479.23   1270.54
## [106]    477.22    601.85    333.79  13557.00    878.46     64.15    340.62
## [113]   1531.39    500.35    448.03    357.11    791.93     13.93    520.35
## [120]    292.58    488.52    139.89    156.49    115.48   1123.42   1071.33
## [127]   3982.11    575.08   3348.11    271.34   1221.26   9945.54   3171.42
## [134]     79.82    227.65     82.96    322.05    489.12    572.58    515.71
## [141]    141.30     78.42    874.89     61.62    881.15    126.48   1141.88
## [148]   1428.67    647.87     88.82   1983.14    428.32    390.65  12652.90
## [155]   1743.69     73.26    295.58    754.28    187.96    187.52    447.60
## [162]    426.93      7.71    228.08    416.46    135.67    252.47     98.62
## [169]   2155.42     92.26   1596.67    584.60    153.68    460.23   1258.39
## [176]    135.71     81.80    223.74    891.28    458.25    117.13    658.22
## [183]    216.58    270.56    262.17      8.05    180.64    160.57     29.94
## [190]    377.60    146.35    347.88   2108.03    699.98   1691.94  11708.60
## [197]    233.94    551.66    483.37     88.39    693.99    668.48    489.58
## [204]    360.49    637.90    544.88    429.92     10.67    228.24    795.47
## [211]    939.88    319.50    336.04   6596.71    698.93    208.98    331.29
## [218]    701.57    554.90     40.21    485.15     79.87     54.06    372.04
## [225]   1001.63     41.97    854.79    822.54   1576.90    324.44   6909.84
## [232]     98.42     98.45    217.43    923.82    331.89    813.98      7.09
## [239]     24.66    243.16    196.86    519.34     37.46    159.21    359.29
## [246]    383.24    543.76    820.43     61.38     20.01    173.66    876.96
## [253]      0.17    149.80     41.42    440.57     63.91     68.27    277.77
## [260]    305.08     19.66     38.91    166.02    465.15    107.62   7023.93
## [267]    313.91     91.47    213.36   1168.03    237.14    449.99    556.72
## [274]     23.93    470.65    512.49    203.52    217.05     53.70    196.97
## [281]    116.19    233.26   6721.34    457.96    100.10    972.12   1530.76
## [288]    140.95   1330.24   1151.36    129.36    730.47     49.27    404.72
## [295]    684.01   1382.90    423.04   1534.03    617.00   1970.27   5150.48
## [302]    820.48    129.81    544.86    446.02    349.45   1011.71    683.75
## [309]     32.88    683.83   2272.00    144.34    475.94    688.32   3746.87
## [316]  13710.20   1205.77     20.87    543.68    719.01    335.87   1291.50
## [323]    398.58    362.16    412.75     70.98    557.16    879.41    369.95
## [330]    768.46     17.64    435.05    315.55   1089.36   4849.31    654.53
## [337]    244.14  13256.90    862.40    241.27    264.21   1949.10    407.88
## [344]   1173.18    485.44    212.58    365.46    738.10    603.48    433.68
## [351]   1827.65    384.62    229.16    742.59     35.23   4391.67    652.46
## [358]   8367.13   1323.35     47.57     71.09    634.80    318.20   1477.07
## [365]    456.72    494.24     37.01   1607.20     13.42    234.60    960.31
## [372]   1156.32   9595.78    600.97    618.86   7091.58   1106.18   2655.89
## [379]  20518.60   4060.69     77.62    355.15   1888.31    320.76    773.91
## [386]      6.50     25.88   1681.76    532.08    208.72   1713.46   1199.93
## [393]    456.15    226.36    164.14   1944.15    748.17   1941.85    744.35
## [400]   2191.45  18351.20    943.00     63.04    401.38   1754.04    279.50
## [407]   4242.50    519.27    428.19    729.65    352.81   1079.16      9.53
## [414]    543.70    272.54   1776.52    282.64   4800.15   2270.29  34513.10
## [421]   3896.34    122.51    748.85   1087.88    636.80   1271.14    838.17
## [428]   3030.47    629.02    894.90   1483.20   2764.54    622.46   1598.44
## [435]   2385.08    221.07   1421.09   3749.53   1044.11    691.62   1127.74
## [442]  19434.50    303.66    611.34   1652.08    596.25    498.96    210.09
## [449]    848.71    722.75    644.66   1661.06    103.71   1801.64    123.72
## [456]    206.09   2609.85   1313.85     17.46   6057.31    107.87   2362.89
## [463]  40893.30   3770.63    241.36    499.73   1287.29    275.05    832.72
## [470]    824.99   2432.58    419.41   2302.42   1479.93    498.09   2106.71
## [477]      5.50    663.04    328.49    171.99   5338.67   5816.30   1513.56
## [484]  13128.40   1910.13    422.90    653.41    619.61    224.34    843.58
## [491]    459.16    296.40    431.55    507.64    538.93    316.14   1389.58
## [498]   1430.00   1403.88  14125.60   1209.50    185.85    138.81   4226.85
## [505]    292.64    497.49    441.68   1859.23    171.51    909.43    944.79
## [512]     29.26   2483.79    133.20    458.40    964.83    687.54     16.56
## [519]    213.04  12388.00    212.89    179.11    886.18    558.24   1199.16
## [526]    203.90     85.73   1197.33    757.71    292.42   2727.48    105.77
## [533]    362.27   2263.32   1499.45   2176.30    791.50  14177.30     68.49
## [540]    125.72   2279.98    235.75   1158.45    382.24    372.92    589.65
## [547]    403.43   2341.83    401.77   1616.43   1252.03     67.22    194.61
## [554]    629.48  10817.20    929.07    137.84    591.71   2671.77    485.28
## [561]    251.56   2970.58    282.30    826.02    737.78    269.63   2476.78
## [568]     26.77   1144.80   1016.19   4418.43   1185.68   2249.89    216.81
## [575]    813.87   3004.24    322.32    665.70     10.19    605.53      7.18
## [582]   2109.64    198.29    285.36    395.95   2352.91   5748.55    518.51
## [589]    149.26     72.22    751.42    622.66    627.20    132.09    436.19
## [596]    233.23   2178.34   1014.78   3103.23    222.45    152.82   1699.98
## [603]    693.40   1990.33   5714.39    245.84    323.70    298.45    348.78
## [610]    185.98   1048.98    194.30    420.67    309.72    957.56    777.37
## [617]     39.66    330.35    258.62    277.92   4111.40    119.59    434.28
## [624]    316.24      5.48    228.28    265.86   1201.20    102.41    723.10
## [631]     39.47    116.78    121.89    966.10   2365.02   8856.87    384.70
## [638]    279.16    856.28    643.53    494.53    276.79    438.82    489.27
## [645]   1117.11    155.39    487.37    357.90    411.14    141.13   1069.34
## [652]    752.56  12740.80   1592.10    724.17  10042.30    127.56    358.62
## [659]    431.14   1064.83     99.86    509.25    890.84    336.03    548.16
## [666]    948.67    415.63    331.71    113.71    251.39   1492.32    164.80
## [673]   1763.26     31.08   2228.22    356.61   3019.34    241.38    620.70
## [680]    414.28    257.91   1416.17     20.72    639.76     99.74    481.03
## [687]    435.73    184.64    746.46    274.71    415.50    351.06   1170.20
## [694]   4792.16    437.54  29973.60    278.77    713.63   1592.06    550.46
## [701]    157.68    418.13   1223.88     37.94    311.95   2090.93    408.57
## [708]   1135.98   1024.90    427.59   1480.23   6687.72   9218.86   8012.80
## [715] 196567.00  13536.00    131.53    504.52    363.71    628.37   3250.02
## [722]   3604.06     74.73   1281.50   4821.65   3029.73   1839.38   2175.30
## [729]  47680.00  11164.10    339.98   5865.03   1010.50   1548.47  18671.50
## [736]   2519.64     59.25    592.99    918.16    274.50   1765.12     26.02
## [743]    687.27    674.77   1318.01    650.69   1331.52    127.16    629.85
## [750]    945.16   4056.11   3336.95    823.05   3583.08     21.36    289.46
## [757]   2432.00  28827.50   6094.45    276.94    635.57   3947.64    820.82
## [764]    729.14   3067.24    195.49   1935.69   3866.28   3532.11    484.08
## [771]    180.92   1529.05    431.03    642.78   3517.98   8084.37   1292.87
## [778]   4267.76    464.86   2700.90  33865.00   5301.34     96.34    325.71
## [785]   2348.19    801.11   1121.43   2947.72    855.53   2739.30    908.48
## [792]    820.14   1218.25   2401.99    286.60    212.56   2758.33   6505.41
## [799]    855.88    440.68   3860.15    401.15   1609.38  18210.20   2346.63
## [806]    202.12    680.91    548.87    755.80    273.80    385.10    406.02
## [813]    167.01    352.52    412.29    761.27    981.94    207.22    820.07
## [820]   1277.46    273.83
range(qt2_5$Weight) #0.17-196567.00
## [1]      0.17 196567.00
# To-do : normalise the weights to better visualise in graph. Convert to csv maybe.

#any(qt2_6$Target) == any(qt2_6$Source)

Graph 3 Analysis:

library(here)
library(tidyverse)

# Load The Data:
qt3 <- data.table::fread(here::here("data", "Q1-Graph3.csv"))
head(qt3)
##    Source eType Target       Time Weight SourceLocation TargetLocation
## 1: 614761     4 514306 -209742644    0.1             NA             NA
## 2: 614761     1 542965    1672686    1.0              1              2
## 3: 538892     1 572391    1749455    1.0              2              2
## 4: 538892     0 614761    2020424    1.0             NA             NA
## 5: 614761     1 500813    2220686    1.0              1              1
## 6: 500813     0 542965    2274331    1.0             NA             NA
##    SourceLatitude SourceLongitude TargetLatitude TargetLongitude
## 1:             NA              NA             NA              NA
## 2:       -27.7842        -8.74823       -21.8960         89.4000
## 3:       -23.5953        91.35710       -21.1411         91.1427
## 4:             NA              NA             NA              NA
## 5:       -27.7842        -8.74823       -29.1714        -10.4930
## 6:             NA              NA             NA              NA
tail(qt3)
##    Source eType Target     Time  Weight SourceLocation TargetLocation
## 1: 500813     5 644226 31536000 1241.29             NA             NA
## 2: 500813     5 632961 31536000  285.60             NA             NA
## 3: 500813     5 473173 31536000 1413.05             NA             NA
## 4: 500813     5 620120 31536000 2892.02             NA             NA
## 5: 500813     5 575030 31536000 7926.69             NA             NA
## 6: 500813     5 621924 31536000  930.98             NA             NA
##    SourceLatitude SourceLongitude TargetLatitude TargetLongitude
## 1:             NA              NA             NA              NA
## 2:             NA              NA             NA              NA
## 3:             NA              NA             NA              NA
## 4:             NA              NA             NA              NA
## 5:             NA              NA             NA              NA
## 6:             NA              NA             NA              NA
# Summarising the Data:
summary(qt3)
##      Source           eType           Target            Time           
##  Min.   :464459   Min.   :0.000   Min.   :459381   Min.   :-209742644  
##  1st Qu.:516236   1st Qu.:5.000   1st Qu.:520084   1st Qu.:  19884838  
##  Median :542649   Median :5.000   Median :567195   Median :  31536000  
##  Mean   :549316   Mean   :3.981   Mean   :556662   Mean   :  25673131  
##  3rd Qu.:578531   3rd Qu.:5.000   3rd Qu.:595581   3rd Qu.:  31536000  
##  Max.   :657076   Max.   :6.000   Max.   :657173   Max.   :  31536000  
##                                                                        
##      Weight         SourceLocation  TargetLocation SourceLatitude   
##  Min.   :     0.1   Min.   :0.000   Min.   :0.00   Min.   :-29.171  
##  1st Qu.:     3.0   1st Qu.:1.000   1st Qu.:1.00   1st Qu.:-25.000  
##  Median :   507.5   Median :2.000   Median :2.00   Median :-22.000  
##  Mean   :  3726.0   Mean   :2.579   Mean   :2.25   Mean   : -7.727  
##  3rd Qu.:  2277.9   3rd Qu.:4.000   3rd Qu.:4.00   3rd Qu.:  2.352  
##  Max.   :159997.0   Max.   :5.000   Max.   :5.00   Max.   : 33.000  
##                     NA's   :641     NA's   :641    NA's   :641      
##  SourceLongitude   TargetLatitude    TargetLongitude  
##  Min.   :-165.00   Min.   :-29.171   Min.   :-165.00  
##  1st Qu.:-161.28   1st Qu.:-23.595   1st Qu.:-111.00  
##  Median : -13.00   Median :-21.141   Median : -26.70  
##  Mean   : -23.88   Mean   : -6.860   Mean   : -20.84  
##  3rd Qu.:  91.00   3rd Qu.:  5.912   3rd Qu.:  91.00  
##  Max.   : 156.00   Max.   : 33.574   Max.   : 156.00  
##  NA's   :641       NA's   :641       NA's   :641
nrow(qt3) #729
## [1] 729
ncol(qt3) #11
## [1] 11
qt3$Source <- as.character(qt3$Source)
qt3$Target <- as.character(qt3$Target)

# Differentiating between channels:
qt3_01 <- qt3 %>% filter(qt3$eType == 0 | qt3$eType == 1) # Communication Channel
nrow(qt3_01) # 160
## [1] 160
qt3_23 <- qt3 %>% filter(qt3$eType == 2 | qt3$eType == 3) # Procurement Channel
nrow(qt3_23) # 12
## [1] 12
qt3_4 <- qt3 %>% filter(qt3$eType == 4) # Co-authorship Channel
nrow(qt3_4) # 1
## [1] 1
qt3_5 <- qt3 %>% filter(qt3$eType == 5) # Demographic Channel
nrow(qt3_5) # 519
## [1] 519
qt3_6 <- qt3 %>% filter(qt3$eType == 6) # Travel Channel
nrow(qt3_6) # 37
## [1] 37
# Highest data for Demographic, Communication and Travel Channel.

# Analysis of the Communication channel:
glimpse(qt3_01)
## Observations: 160
## Variables: 11
## $ Source          <chr> "614761", "538892", "538892", "614761", "50081...
## $ eType           <int> 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1...
## $ Target          <chr> "542965", "572391", "614761", "500813", "54296...
## $ Time            <int> 1672686, 1749455, 2020424, 2220686, 2274331, 2...
## $ Weight          <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1...
## $ SourceLocation  <int> 1, 2, NA, 1, NA, NA, NA, 1, NA, 1, 1, NA, 2, 1...
## $ TargetLocation  <int> 2, 2, NA, 1, NA, NA, NA, 2, NA, 1, 1, NA, 1, 2...
## $ SourceLatitude  <dbl> -27.7842, -23.5953, NA, -27.7842, NA, NA, NA, ...
## $ SourceLongitude <dbl> -8.74823, 91.35710, NA, -8.74823, NA, NA, NA, ...
## $ TargetLatitude  <dbl> -21.8960, -21.1411, NA, -29.1714, NA, NA, NA, ...
## $ TargetLongitude <dbl> 89.40000, 91.14270, NA, -10.49300, NA, NA, NA,...
#unique(qt3_01)
unique(qt3_01$eType) # 0 1
## [1] 1 0
unique(qt3_01$SourceLocation) # 1  2 NA  4  5  0
## [1]  1  2 NA  4  5  0
unique(qt3_01$TargetLocation) # 2 NA  1  0  4  5
## [1]  2 NA  1  0  4  5
unique(qt3_01$SourceLatitude) # -27.78420 -23.59530 NA -29.17140   5.91178  24.98310  32.11920   2.35166
## [1] -27.78420 -23.59530        NA -29.17140   5.91178  24.98310  32.11920
## [8]   2.35166
unique(qt3_01$SourceLongitude)# -8.74823 91.35710 NA -10.49300 -161.27600  155.44600  -47.35310 -161.32200 
## [1]   -8.74823   91.35710         NA  -10.49300 -161.27600  155.44600
## [7]  -47.35310 -161.32200
unique(qt3_01$TargetLatitude) # -21.89600 -21.14110        NA -29.17140 -27.78420 -23.59530  33.57410   2.35166  32.11920  24.98310 5.91178
##  [1] -21.89600 -21.14110        NA -29.17140 -27.78420 -23.59530  33.57410
##  [8]   2.35166  32.11920  24.98310   5.91178
unique(qt3_01$TargetLongitude) #  89.40000   91.14270         NA  -10.49300   -8.74823   91.35710  -40.39040 -161.32200  -47.35310 155.44600 -161.27600
##  [1]   89.40000   91.14270         NA  -10.49300   -8.74823   91.35710
##  [7]  -40.39040 -161.32200  -47.35310  155.44600 -161.27600
unique(qt3_01$Source) 
##  [1] "614761" "538892" "500813" "493094" "536003" "521318" "542649"
##  [8] "572391" "541619" "544074" "493652" "516236" "607386"
unique(qt3_01$Target) 
##  [1] "542965" "572391" "614761" "500813" "538892" "493094" "536003"
##  [8] "521318" "607386" "516236" "493652" "542649" "544074" "541619"
colnames(qt3_01)
##  [1] "Source"          "eType"           "Target"         
##  [4] "Time"            "Weight"          "SourceLocation" 
##  [7] "TargetLocation"  "SourceLatitude"  "SourceLongitude"
## [10] "TargetLatitude"  "TargetLongitude"
# Analysis of the Demographic channel:
glimpse(qt3_5)
## Observations: 519
## Variables: 11
## $ Source          <chr> "610497", "610497", "552988", "610497", "61049...
## $ eType           <int> 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5...
## $ Target          <chr> "640784", "630626", "610497", "567195", "52744...
## $ Time            <int> 31536000, 31536000, 31536000, 31536000, 315360...
## $ Weight          <dbl> 271.92, 961.13, 3704.63, 2020.36, 164.35, 516....
## $ SourceLocation  <int> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
## $ TargetLocation  <int> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
## $ SourceLatitude  <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
## $ SourceLongitude <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
## $ TargetLatitude  <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
## $ TargetLongitude <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
#unique(qt3_5)
unique(qt3_5$eType) # 5
## [1] 5
unique(qt3_5$SourceLocation) # NA
## [1] NA
unique(qt3_5$TargetLocation) # NA
## [1] NA
unique(qt3_5$SourceLatitude) # NA
## [1] NA
unique(qt3_5$SourceLongitude) # NA
## [1] NA
unique(qt3_5$TargetLatitude) # NA
## [1] NA
unique(qt3_5$TargetLongitude) # NA
## [1] NA
unique(qt3_5$Source)
##  [1] "610497" "552988" "578531" "510031" "657076" "478754" "575295"
##  [8] "568284" "508898" "538892" "620120" "572391" "542965" "536951"
## [15] "466976" "607386" "628223" "516236" "492701" "584736" "520084"
## [22] "529433" "493094" "604113" "493652" "544074" "541619" "614761"
## [29] "500813"
unique(qt3_5$Target)
##  [1] "640784" "630626" "610497" "567195" "527449" "459381" "595298"
##  [8] "466907" "589943" "537281" "523927" "580426" "616315" "503701"
## [15] "632961" "473173" "620120" "575030" "503218" "578531" "606730"
## [22] "577992" "642329" "621924" "657076" "478754" "571970" "575295"
## [29] "595581" "568284" "508898" "538892" "572391" "542965" "536951"
## [36] "466976" "607386" "628223" "516236" "536346" "520660" "492701"
## [43] "644226" "584736" "520084" "529433" "493094" "604113" "493652"
## [50] "544074" "541619" "614761" "500813"
unique(qt3_5$Weight)
##   [1]    271.92    961.13   3704.63   2020.36    164.35    516.88    707.62
##   [8]    382.90    299.92    476.32    191.06    180.33    365.16   1626.32
##  [15]    196.78     91.95    119.20   3200.70    127.15    794.95   5216.01
##  [22]    535.49  44432.60   4032.44    112.79    564.37   3687.96    604.91
##  [29]   1122.89   1464.95   4967.63    951.82   1875.25    765.20     94.12
##  [36]    842.49   2131.32    779.39    979.19   6814.56   3994.14   1367.71
##  [43]    983.51   4887.83  36157.50    384.30    595.71   2596.98    458.72
##  [50]   1950.69    530.82   1922.91    501.28   1384.47    719.92    180.60
##  [57]    242.37   5823.53   7256.03   1257.76   6376.02    197.45  29465.30
##  [64]    334.00    546.44   1567.57   1232.64   1763.76    179.32    904.42
##  [71]    671.78    885.78    132.51    105.23   2312.74   2277.90    611.39
##  [78]   1131.09  25163.80    516.47    173.64   1609.94    429.42   2117.18
##  [85]    277.44   1211.81   1191.34      2.91    280.94     60.24    281.97
##  [92]   2150.02   1213.18   5529.22   1638.18   5053.94   7039.65   1147.37
##  [99]    285.70    267.45   3054.32    701.36    369.91    279.83    141.32
## [106]    584.34   1772.19    955.54    818.09   2456.28     92.37    439.20
## [113]   3084.78    164.30   3861.34    817.27   1437.55   7216.68   2664.62
## [120]  50214.10   5377.20     73.45    624.98   2939.52   1068.85   2951.76
## [127]   1414.30   3035.49    384.00   1272.62    187.12   3744.72   1245.58
## [134]  13481.80  19974.00   1053.33    612.53   7866.03    804.60     66.56
## [141]    206.85   2929.23    411.67   1336.50   2087.94    115.09    318.53
## [148]    287.96   1700.68    232.76    397.53   1256.32   2011.04   7084.51
## [155]    323.44   9063.18    593.37    377.58    330.92    642.73    288.38
## [162]   1117.58    619.38    315.44    140.14    253.64   1960.88    214.29
## [169]    787.03   1472.17   7690.99   3433.52  14865.80   1031.52    149.53
## [176]    737.83   3375.37    177.36    232.68    136.94   1100.57    613.80
## [183]   1637.51   1420.57    415.80    210.09    373.32    310.96    804.21
## [190]   8413.60    798.15   1252.81   5234.64   4019.67    507.47    200.63
## [197]   1391.04    620.27    449.32   2552.28    421.71    475.36    394.63
## [204]    954.38   2141.56   1414.94   3296.54    221.54   1187.43   4620.27
## [211]  38019.80    640.95   2249.28   7533.16    576.32   3435.72   3963.81
## [218]    848.82   3202.79   1652.08   5169.73    168.32    723.89   7146.89
## [225]    248.90   5749.62   3816.99    915.56  67455.80   3985.69    352.43
## [232]    174.81   5638.62   2396.91    622.79    170.71   4129.17    790.97
## [239]    618.59   2377.76   6084.53    347.93   3632.97    601.22  18698.10
## [246]   2016.27   2582.67   8091.25   1129.49  86251.60   9336.13    576.14
## [253]    978.47   8384.06   1096.37   1846.53    948.57   4632.30     30.83
## [260]   3739.59   4394.98   7443.20    304.78    520.28   6636.04   4485.42
## [267]  19153.40   1117.73  39291.80   6908.27 159997.00  32142.30    713.06
## [274]   1904.74   1406.81   1929.22   6938.77   5302.10   2618.50   8956.10
## [281]  11185.40   4836.31   2574.66    280.38    353.31   2489.02 146800.00
## [288]  41464.40  47400.00   1399.05   9335.04   6111.55   4744.49  39167.10
## [295]    170.12   1819.60   8665.54   1433.99   4463.25   2261.47   3006.51
## [302]   3052.63   2193.96    251.90   2367.25    532.37    612.60   4436.30
## [309]  16279.80  19167.70 134196.00  26846.90    494.71   2778.19   7045.08
## [316]    534.07  12526.90   6214.69   1500.31  15399.50    535.85   6650.38
## [323]   5190.51    117.94   1100.50   8001.41  11520.60  15668.20   1761.31
## [330]  10072.20   3978.84   2024.70  11179.50 129601.00  17907.00    522.39
## [337]    994.25   2315.62   1531.51  15080.30   8845.36   2262.18   5343.67
## [344]   2588.29  13260.70   2230.88  16249.60   2347.91   2580.06    530.03
## [351]  20358.50  30415.80   3538.33  13854.70   4349.74   1284.37  10862.70
## [358] 121408.00   6540.34   1415.99   1597.54   1812.17   2716.27   3419.82
## [365]   3143.13   8060.60    460.34   5167.03   2514.63   4385.38    684.27
## [372]    210.50   2158.60   1017.67   6453.51  13393.60  15821.90   6900.20
## [379]  10157.60  79413.80   6315.32   1159.64   1793.02   2799.86   1723.73
## [386]   4391.21     78.87  10214.80   1173.68   1631.93   4803.92   3163.52
## [393]    616.21   3725.96   3582.65   2441.93    115.29   2933.47    102.25
## [400]    153.88    698.03    926.20    233.46    539.30    323.11     53.94
## [407]    437.88    402.74    449.99      1.53    435.11    154.55    796.54
## [414]    735.72  15445.80   2055.58    142.76    156.76   1299.03    336.29
## [421]    120.27    304.65   1011.58    214.43    284.93    490.95   1132.00
## [428]     38.67     78.12   1651.44   1018.22   8492.89     85.67    173.45
## [435]   5639.96   1003.13    139.33    259.10    370.86    132.61    233.70
## [442]     73.43    114.21    382.88     18.12    376.40    447.16    567.43
## [449]      4.52    592.22    243.68   2345.31   1088.77    444.32    713.50
## [456]   4553.79     26.11     75.27    218.46    208.62    231.44    577.37
## [463]     16.34     92.30    263.52    125.82    588.78    669.26     21.65
## [470]    574.32      4.93    146.40     85.13   1085.42     72.99   2793.29
## [477]    283.97   4471.64   2505.35  24662.90     11.82    663.33   1026.74
## [484]    584.32    847.85    425.54   3508.30     17.14    460.73    532.11
## [491]   1698.46    489.33   2501.87   2556.09   5740.10    185.98   3233.06
## [498]   1861.41   1208.09  26707.80   3517.64    162.65    340.32    703.66
## [505]    243.26   2066.72    635.44   2511.22    249.16    708.12   1122.43
## [512]   1552.37    161.16   1241.29    285.60   1413.05   2892.02   7926.69
## [519]    930.98
qt3_5 <- subset(qt3_5, select = -c(SourceLocation, TargetLocation, SourceLatitude, SourceLongitude, TargetLatitude, TargetLongitude)) # SOurce and Target Latitude and Longitude columns removed as all Null.
colnames(qt3_5)
## [1] "Source" "eType"  "Target" "Time"   "Weight"
range(qt3_5$Source) # 466976 657076
## [1] "466976" "657076"
range(qt3_5$Target) # 459381 657076
## [1] "459381" "657076"
range(qt3_5$Time) # 31536000-31536000
## [1] 31536000 31536000
income_cat_qt3 <- NULL
# Income Categories:
for (i in (qt3_5$Source)) {
  for (j in (cat$NodeID)) {                   # cat_list contains all the demographic nodeIDs (from the DemographicNodeExtraction Script)
    if(i == j){
      income_cat_qt3 <- append(income_cat_qt3,i)
    }
  }
}

print(income_cat_qt3) # income categories extracted
##  [1] "552988" "510031" "552988" "552988" "510031" "552988" "552988"
##  [8] "552988" "510031" "552988" "510031" "552988" "620120" "510031"
## [15] "552988" "620120" "552988" "552988" "552988" "510031" "552988"
## [22] "620120" "510031" "552988" "510031" "552988" "552988" "552988"
## [29] "510031" "552988" "510031" "552988" "552988" "510031" "552988"
## [36] "620120" "510031" "552988" "510031" "552988" "552988" "510031"
## [43] "552988" "552988"
unique(income_cat_qt3) # 3
## [1] "552988" "510031" "620120"
qt3_5_sub1 <- subset(qt3_5, qt3_5$Source == income_cat_qt3) # Subset of data with only income categories
## Warning in qt3_5$Source == income_cat_qt3: longer object length is not a
## multiple of shorter object length
str(qt3_5_sub1)
## 'data.frame':    25 obs. of  5 variables:
##  $ Source: chr  "552988" "552988" "552988" "552988" ...
##  $ eType : int  5 5 5 5 5 5 5 5 5 5 ...
##  $ Target: chr  "610497" "657076" "478754" "575295" ...
##  $ Time  : int  31536000 31536000 31536000 31536000 31536000 31536000 31536000 31536000 31536000 31536000 ...
##  $ Weight: num  3705 36158 29465 25164 2665 ...
plot(qt3_5_sub1$Source, qt3_5_sub1$Weight) # Plot of Monetary income in each category

# Expense Categories:
expense_cat_qt3 <- NULL
for (k in qt3_5$Target) {
  for(l in cat$NodeID){ 
    if(k==l){
      expense_cat_qt3 <- append(expense_cat_qt3, k)
    }
  }
  
}
print(expense_cat_qt3) # expense categories extracted
##   [1] "640784" "630626" "567195" "527449" "459381" "595298" "466907"
##   [8] "589943" "537281" "523927" "580426" "616315" "503701" "632961"
##  [15] "473173" "620120" "575030" "640784" "503218" "630626" "567195"
##  [22] "527449" "459381" "595298" "466907" "606730" "589943" "577992"
##  [29] "537281" "523927" "580426" "616315" "642329" "503701" "632961"
##  [36] "473173" "620120" "575030" "621924" "640784" "630626" "527449"
##  [43] "459381" "595298" "466907" "589943" "537281" "523927" "580426"
##  [50] "616315" "642329" "503701" "473173" "620120" "575030" "621924"
##  [57] "630626" "527449" "459381" "595298" "466907" "589943" "577992"
##  [64] "523927" "616315" "642329" "571970" "632961" "473173" "620120"
##  [71] "621924" "630626" "527449" "459381" "595298" "466907" "577992"
##  [78] "537281" "523927" "595581" "616315" "642329" "571970" "632961"
##  [85] "473173" "620120" "575030" "621924" "630626" "567195" "527449"
##  [92] "459381" "595298" "466907" "589943" "577992" "537281" "523927"
##  [99] "595581" "616315" "642329" "503701" "571970" "632961" "473173"
## [106] "620120" "575030" "621924" "503218" "630626" "567195" "527449"
## [113] "459381" "595298" "466907" "589943" "537281" "523927" "580426"
## [120] "595581" "642329" "503701" "473173" "620120" "575030" "621924"
## [127] "567195" "527449" "459381" "595298" "466907" "589943" "577992"
## [134] "537281" "523927" "580426" "642329" "632961" "473173" "575030"
## [141] "621924" "567195" "527449" "459381" "595298" "466907" "589943"
## [148] "577992" "537281" "580426" "616315" "503701" "632961" "473173"
## [155] "575030" "621924" "567195" "527449" "459381" "595298" "466907"
## [162] "589943" "537281" "523927" "580426" "595581" "616315" "642329"
## [169] "571970" "632961" "473173" "620120" "575030" "621924" "503218"
## [176] "567195" "527449" "459381" "595298" "466907" "589943" "577992"
## [183] "537281" "523927" "580426" "595581" "616315" "642329" "503701"
## [190] "473173" "620120" "575030" "527449" "459381" "595298" "466907"
## [197] "589943" "577992" "537281" "523927" "642329" "503701" "571970"
## [204] "632961" "473173" "620120" "575030" "621924" "567195" "527449"
## [211] "459381" "595298" "466907" "589943" "537281" "523927" "580426"
## [218] "595581" "642329" "503701" "632961" "473173" "575030" "621924"
## [225] "503218" "630626" "567195" "527449" "459381" "595298" "466907"
## [232] "606730" "537281" "523927" "580426" "595581" "642329" "503701"
## [239] "571970" "632961" "473173" "620120" "575030" "621924" "630626"
## [246] "567195" "527449" "459381" "595298" "466907" "589943" "537281"
## [253] "523927" "580426" "595581" "616315" "503701" "571970" "632961"
## [260] "473173" "620120" "575030" "621924" "503218" "630626" "536346"
## [267] "520660" "527449" "459381" "595298" "466907" "589943" "523927"
## [274] "595581" "616315" "642329" "571970" "644226" "632961" "473173"
## [281] "620120" "575030" "630626" "567195" "527449" "459381" "595298"
## [288] "466907" "589943" "523927" "580426" "595581" "616315" "642329"
## [295] "503701" "571970" "632961" "473173" "620120" "621924" "640784"
## [302] "630626" "536346" "520660" "567195" "527449" "459381" "595298"
## [309] "466907" "589943" "577992" "537281" "523927" "580426" "595581"
## [316] "642329" "503701" "644226" "632961" "473173" "620120" "575030"
## [323] "640784" "630626" "536346" "520660" "567195" "527449" "459381"
## [330] "595298" "466907" "606730" "589943" "577992" "537281" "523927"
## [337] "580426" "616315" "642329" "503701" "644226" "632961" "473173"
## [344] "620120" "575030" "621924" "630626" "567195" "527449" "459381"
## [351] "595298" "466907" "589943" "577992" "523927" "580426" "616315"
## [358] "642329" "503701" "571970" "473173" "620120" "621924" "567195"
## [365] "527449" "459381" "595298" "466907" "537281" "523927" "580426"
## [372] "616315" "642329" "503701" "632961" "473173" "621924" "567195"
## [379] "527449" "459381" "595298" "466907" "577992" "537281" "523927"
## [386] "595581" "616315" "642329" "503701" "571970" "632961" "473173"
## [393] "620120" "575030" "621924" "567195" "527449" "459381" "595298"
## [400] "466907" "589943" "577992" "537281" "523927" "580426" "595581"
## [407] "616315" "503701" "632961" "473173" "620120" "575030" "630626"
## [414] "536346" "520660" "567195" "527449" "459381" "595298" "466907"
## [421] "589943" "577992" "537281" "523927" "580426" "595581" "616315"
## [428] "642329" "503701" "571970" "644226" "632961" "473173" "620120"
## [435] "575030" "621924" "630626" "527449" "459381" "595298" "466907"
## [442] "577992" "537281" "523927" "580426" "616315" "642329" "503701"
## [449] "632961" "473173" "620120" "575030" "640784" "630626" "536346"
## [456] "520660" "567195" "527449" "459381" "595298" "466907" "577992"
## [463] "537281" "523927" "580426" "616315" "642329" "503701" "571970"
## [470] "644226" "632961" "473173" "620120" "575030" "621924"
unique(expense_cat_qt3) # 27
##  [1] "640784" "630626" "567195" "527449" "459381" "595298" "466907"
##  [8] "589943" "537281" "523927" "580426" "616315" "503701" "632961"
## [15] "473173" "620120" "575030" "503218" "606730" "577992" "642329"
## [22] "621924" "571970" "595581" "536346" "520660" "644226"
qt3_5_sub2 <- subset(qt3_5, qt3_5$Target == expense_cat_qt3) # Subset of data with only expense categories
## Warning in qt3_5$Target == expense_cat_qt3: longer object length is not a
## multiple of shorter object length
str(qt3_5_sub2)
## 'data.frame':    29 obs. of  5 variables:
##  $ Source: chr  "610497" "610497" "572391" "572391" ...
##  $ eType : int  5 5 5 5 5 5 5 5 5 5 ...
##  $ Target: chr  "640784" "630626" "567195" "527449" ...
##  $ Time  : int  31536000 31536000 31536000 31536000 31536000 31536000 31536000 31536000 31536000 31536000 ...
##  $ Weight: num  272 961 593 378 331 ...
plot(qt3_5_sub2$Target, qt3_5_sub2$Weight) # Plot of Monetary expenses in each category

hist(qt3_5$Weight)

unique(qt3_5$Weight)
##   [1]    271.92    961.13   3704.63   2020.36    164.35    516.88    707.62
##   [8]    382.90    299.92    476.32    191.06    180.33    365.16   1626.32
##  [15]    196.78     91.95    119.20   3200.70    127.15    794.95   5216.01
##  [22]    535.49  44432.60   4032.44    112.79    564.37   3687.96    604.91
##  [29]   1122.89   1464.95   4967.63    951.82   1875.25    765.20     94.12
##  [36]    842.49   2131.32    779.39    979.19   6814.56   3994.14   1367.71
##  [43]    983.51   4887.83  36157.50    384.30    595.71   2596.98    458.72
##  [50]   1950.69    530.82   1922.91    501.28   1384.47    719.92    180.60
##  [57]    242.37   5823.53   7256.03   1257.76   6376.02    197.45  29465.30
##  [64]    334.00    546.44   1567.57   1232.64   1763.76    179.32    904.42
##  [71]    671.78    885.78    132.51    105.23   2312.74   2277.90    611.39
##  [78]   1131.09  25163.80    516.47    173.64   1609.94    429.42   2117.18
##  [85]    277.44   1211.81   1191.34      2.91    280.94     60.24    281.97
##  [92]   2150.02   1213.18   5529.22   1638.18   5053.94   7039.65   1147.37
##  [99]    285.70    267.45   3054.32    701.36    369.91    279.83    141.32
## [106]    584.34   1772.19    955.54    818.09   2456.28     92.37    439.20
## [113]   3084.78    164.30   3861.34    817.27   1437.55   7216.68   2664.62
## [120]  50214.10   5377.20     73.45    624.98   2939.52   1068.85   2951.76
## [127]   1414.30   3035.49    384.00   1272.62    187.12   3744.72   1245.58
## [134]  13481.80  19974.00   1053.33    612.53   7866.03    804.60     66.56
## [141]    206.85   2929.23    411.67   1336.50   2087.94    115.09    318.53
## [148]    287.96   1700.68    232.76    397.53   1256.32   2011.04   7084.51
## [155]    323.44   9063.18    593.37    377.58    330.92    642.73    288.38
## [162]   1117.58    619.38    315.44    140.14    253.64   1960.88    214.29
## [169]    787.03   1472.17   7690.99   3433.52  14865.80   1031.52    149.53
## [176]    737.83   3375.37    177.36    232.68    136.94   1100.57    613.80
## [183]   1637.51   1420.57    415.80    210.09    373.32    310.96    804.21
## [190]   8413.60    798.15   1252.81   5234.64   4019.67    507.47    200.63
## [197]   1391.04    620.27    449.32   2552.28    421.71    475.36    394.63
## [204]    954.38   2141.56   1414.94   3296.54    221.54   1187.43   4620.27
## [211]  38019.80    640.95   2249.28   7533.16    576.32   3435.72   3963.81
## [218]    848.82   3202.79   1652.08   5169.73    168.32    723.89   7146.89
## [225]    248.90   5749.62   3816.99    915.56  67455.80   3985.69    352.43
## [232]    174.81   5638.62   2396.91    622.79    170.71   4129.17    790.97
## [239]    618.59   2377.76   6084.53    347.93   3632.97    601.22  18698.10
## [246]   2016.27   2582.67   8091.25   1129.49  86251.60   9336.13    576.14
## [253]    978.47   8384.06   1096.37   1846.53    948.57   4632.30     30.83
## [260]   3739.59   4394.98   7443.20    304.78    520.28   6636.04   4485.42
## [267]  19153.40   1117.73  39291.80   6908.27 159997.00  32142.30    713.06
## [274]   1904.74   1406.81   1929.22   6938.77   5302.10   2618.50   8956.10
## [281]  11185.40   4836.31   2574.66    280.38    353.31   2489.02 146800.00
## [288]  41464.40  47400.00   1399.05   9335.04   6111.55   4744.49  39167.10
## [295]    170.12   1819.60   8665.54   1433.99   4463.25   2261.47   3006.51
## [302]   3052.63   2193.96    251.90   2367.25    532.37    612.60   4436.30
## [309]  16279.80  19167.70 134196.00  26846.90    494.71   2778.19   7045.08
## [316]    534.07  12526.90   6214.69   1500.31  15399.50    535.85   6650.38
## [323]   5190.51    117.94   1100.50   8001.41  11520.60  15668.20   1761.31
## [330]  10072.20   3978.84   2024.70  11179.50 129601.00  17907.00    522.39
## [337]    994.25   2315.62   1531.51  15080.30   8845.36   2262.18   5343.67
## [344]   2588.29  13260.70   2230.88  16249.60   2347.91   2580.06    530.03
## [351]  20358.50  30415.80   3538.33  13854.70   4349.74   1284.37  10862.70
## [358] 121408.00   6540.34   1415.99   1597.54   1812.17   2716.27   3419.82
## [365]   3143.13   8060.60    460.34   5167.03   2514.63   4385.38    684.27
## [372]    210.50   2158.60   1017.67   6453.51  13393.60  15821.90   6900.20
## [379]  10157.60  79413.80   6315.32   1159.64   1793.02   2799.86   1723.73
## [386]   4391.21     78.87  10214.80   1173.68   1631.93   4803.92   3163.52
## [393]    616.21   3725.96   3582.65   2441.93    115.29   2933.47    102.25
## [400]    153.88    698.03    926.20    233.46    539.30    323.11     53.94
## [407]    437.88    402.74    449.99      1.53    435.11    154.55    796.54
## [414]    735.72  15445.80   2055.58    142.76    156.76   1299.03    336.29
## [421]    120.27    304.65   1011.58    214.43    284.93    490.95   1132.00
## [428]     38.67     78.12   1651.44   1018.22   8492.89     85.67    173.45
## [435]   5639.96   1003.13    139.33    259.10    370.86    132.61    233.70
## [442]     73.43    114.21    382.88     18.12    376.40    447.16    567.43
## [449]      4.52    592.22    243.68   2345.31   1088.77    444.32    713.50
## [456]   4553.79     26.11     75.27    218.46    208.62    231.44    577.37
## [463]     16.34     92.30    263.52    125.82    588.78    669.26     21.65
## [470]    574.32      4.93    146.40     85.13   1085.42     72.99   2793.29
## [477]    283.97   4471.64   2505.35  24662.90     11.82    663.33   1026.74
## [484]    584.32    847.85    425.54   3508.30     17.14    460.73    532.11
## [491]   1698.46    489.33   2501.87   2556.09   5740.10    185.98   3233.06
## [498]   1861.41   1208.09  26707.80   3517.64    162.65    340.32    703.66
## [505]    243.26   2066.72    635.44   2511.22    249.16    708.12   1122.43
## [512]   1552.37    161.16   1241.29    285.60   1413.05   2892.02   7926.69
## [519]    930.98
range(qt3_5$Weight) #1.53 159997.00
## [1]      1.53 159997.00
# To-do : normalise the weights to better visualise in graph. Convert to csv maybe.

Graph 4 Analysis:

# Load The Data:
qt4 <- data.table::fread(here::here("data", "Q1-Graph4.csv"))
head(qt4)
##    Source eType Target    Time Weight SourceLocation TargetLocation
## 1: 636721     2 585417   98586   1398             NA             NA
## 2: 628320     1 557269  186326      1              4              4
## 3: 546593     1 492850  211842      1              0              3
## 4: 536906     0 569329  925206      1             NA             NA
## 5: 483005     0 655963 1214644      1             NA             NA
## 6: 601496     0 557269 1233608      1             NA             NA
##    SourceLatitude SourceLongitude TargetLatitude TargetLongitude
## 1:             NA              NA             NA              NA
## 2:       0.224078       -163.6240        2.40053        -161.288
## 3:      32.214600        -42.6609      -24.99040        -111.346
## 4:             NA              NA             NA              NA
## 5:             NA              NA             NA              NA
## 6:             NA              NA             NA              NA
tail(qt4)
##    Source eType Target     Time  Weight SourceLocation TargetLocation
## 1: 541907     5 503701 31536000  435.81             NA             NA
## 2: 541907     5 632961 31536000  114.54             NA             NA
## 3: 541907     5 473173 31536000   43.82             NA             NA
## 4: 510031     5 541907 31536000  357.94             NA             NA
## 5: 552988     5 541907 31536000 7219.68             NA             NA
## 6: 620120     5 541907 31536000    7.79             NA             NA
##    SourceLatitude SourceLongitude TargetLatitude TargetLongitude
## 1:             NA              NA             NA              NA
## 2:             NA              NA             NA              NA
## 3:             NA              NA             NA              NA
## 4:             NA              NA             NA              NA
## 5:             NA              NA             NA              NA
## 6:             NA              NA             NA              NA
# Summarising the Data:
summary(qt4)
##      Source           eType           Target            Time         
##  Min.   :464579   Min.   :0.000   Min.   :459381   Min.   :   98586  
##  1st Qu.:510031   1st Qu.:5.000   1st Qu.:527449   1st Qu.:26425410  
##  Median :566580   Median :5.000   Median :577992   Median :31536000  
##  Mean   :557659   Mean   :4.463   Mean   :568697   Mean   :26478065  
##  3rd Qu.:585606   3rd Qu.:5.000   3rd Qu.:620120   3rd Qu.:31536000  
##  Max.   :657526   Max.   :6.000   Max.   :657526   Max.   :31536000  
##                                                                      
##      Weight         SourceLocation  TargetLocation  SourceLatitude   
##  Min.   :    -1.0   Min.   :0.000   Min.   :0.000   Min.   :-29.676  
##  1st Qu.:     3.0   1st Qu.:0.000   1st Qu.:1.000   1st Qu.:-24.993  
##  Median :   337.5   Median :2.000   Median :3.000   Median :  2.401  
##  Mean   :  2154.4   Mean   :2.085   Mean   :2.534   Mean   :  3.742  
##  3rd Qu.:  1370.2   3rd Qu.:3.250   3rd Qu.:4.000   3rd Qu.: 33.000  
##  Max.   :141744.0   Max.   :5.000   Max.   :5.000   Max.   : 39.889  
##                     NA's   :556     NA's   :556     NA's   :556      
##  SourceLongitude   TargetLatitude     TargetLongitude  
##  Min.   :-165.00   Min.   :-35.6034   Min.   :-168.96  
##  1st Qu.:-111.00   1st Qu.:-25.0000   1st Qu.:-111.00  
##  Median : -41.00   Median :  1.0000   Median : -41.78  
##  Mean   : -23.21   Mean   :  0.5186   Mean   : -35.92  
##  3rd Qu.:  91.00   3rd Qu.: 22.1073   3rd Qu.: -11.44  
##  Max.   : 156.00   Max.   : 39.8886   Max.   : 156.26  
##  NA's   :556       NA's   :556        NA's   :556
nrow(qt4) #732
## [1] 732
ncol(qt4) #11
## [1] 11
qt4$Source <- as.character(qt4$Source)
qt4$Target <- as.character(qt4$Target)

# Differentiating between channels:
qt4_01 <- qt4 %>% filter(qt4$eType == 0 | qt4$eType == 1) # Communication Channel
nrow(qt4_01) # 106
## [1] 106
qt4_23 <- qt4 %>% filter(qt4$eType == 2 | qt4$eType == 3) # Procurement Channel
nrow(qt4_23) # 17
## [1] 17
qt4_4 <- qt4 %>% filter(qt4$eType == 4) # Co-authorship Channel
nrow(qt4_4) # 0
## [1] 0
qt4_5 <- qt4 %>% filter(qt4$eType == 5) # Demographic Channel
nrow(qt4_5) # 494
## [1] 494
qt4_6 <- qt4 %>% filter(qt4$eType == 6) # Travel Channel
nrow(qt4_6) # 115
## [1] 115
# Highest data for Demographic, Communication and Travel Channel.

# Analysis of the Communication channel:
glimpse(qt4_01)
## Observations: 106
## Variables: 11
## $ Source          <chr> "628320", "546593", "536906", "483005", "60149...
## $ eType           <int> 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0...
## $ Target          <chr> "557269", "492850", "569329", "655963", "55726...
## $ Time            <int> 186326, 211842, 925206, 1214644, 1233608, 1648...
## $ Weight          <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1...
## $ SourceLocation  <int> 4, 0, NA, NA, NA, 5, 4, 0, NA, NA, NA, NA, 0, ...
## $ TargetLocation  <int> 4, 3, NA, NA, NA, 5, 3, 3, NA, NA, NA, NA, 3, ...
## $ SourceLatitude  <dbl> 0.224078, 32.214600, NA, NA, NA, 21.543400, 2....
## $ SourceLongitude <dbl> -163.6240, -42.6609, NA, NA, NA, 154.2790, -16...
## $ TargetLatitude  <dbl> 2.40053, -24.99040, NA, NA, NA, 21.54340, -23....
## $ TargetLongitude <dbl> -161.288, -111.346, NA, NA, NA, 154.279, -111....
#unique(qt4_01)
unique(qt4_01$eType) # 0 1
## [1] 1 0
unique(qt4_01$SourceLocation) # 4  0 NA  5  1  3
## [1]  4  0 NA  5  1  3
unique(qt4_01$TargetLocation) # 4  3 NA  5  2  1  0
## [1]  4  3 NA  5  2  1  0
unique(qt4_01$SourceLatitude) 
##  [1]   0.224078  32.214600         NA  21.543400   2.400530  39.888600
##  [7]  28.742600  22.429000  33.783300 -25.732900 -23.875500   3.004860
## [13] -25.232400 -29.676400  29.416200 -24.475000 -24.990400 -24.575600
## [19]  19.138600
unique(qt4_01$SourceLongitude)
##  [1] -163.6240  -42.6609        NA  154.2790 -161.2880  -41.7780  -41.4508
##  [8]  154.8590  -45.4927  -14.9697 -111.5410 -159.2300 -110.1800  -11.6307
## [15]  -45.8675 -111.1470 -111.3460 -110.9450  155.0990
unique(qt4_01$TargetLatitude) 
##  [1]   2.400530 -24.990400         NA  21.543400 -23.875500 -24.575600
##  [7]   3.004860 -22.066000 -32.706500  22.429000  39.888600   0.224078
## [13] -25.178100  28.742600  29.416200 -24.475000 -24.037600 -21.154500
## [19] -35.603400 -24.929700   5.330310  20.783900 -24.066100  20.100500
## [25]  33.783300 -27.058200  39.457100 -24.374800 -25.232400  -3.350860
unique(qt4_01$TargetLongitude) 
##  [1] -161.2880 -111.3460        NA  154.2790 -111.5410 -110.9450 -159.2300
##  [8]   93.1290  -10.3259  154.8590  -41.7780 -163.6240 -110.1440  -41.4508
## [15]  -45.8675 -111.1470 -110.7300   88.0749  -11.7988 -111.0140 -168.9570
## [22]  156.2560 -111.9360  154.0040  -45.4927  -10.3526  -48.4240 -111.2570
## [29] -110.1800 -162.1800
unique(qt4_01$Source) 
##  [1] "628320" "546593" "536906" "483005" "601496" "639642" "557269"
##  [8] "579305" "584457" "516873" "492850" "569329" "544636" "580798"
## [15] "464579" "636721" "566580" "657526" "588172" "585606" "655963"
## [22] "541907" "482012"
unique(qt4_01$Target) 
##  [1] "557269" "492850" "569329" "655963" "639642" "544636" "483005"
##  [8] "580798" "584457" "482012" "541907" "611572" "601496" "588172"
## [15] "546593" "516873" "585606" "580237" "536906" "579305" "628320"
## [22] "571369" "596726" "537816" "657526" "464579" "558089" "459726"
## [29] "578749" "571670" "500336" "566580" "636721" "623468" "477374"
## [36] "611238" "521673" "516393" "645371"
colnames(qt4_01)
##  [1] "Source"          "eType"           "Target"         
##  [4] "Time"            "Weight"          "SourceLocation" 
##  [7] "TargetLocation"  "SourceLatitude"  "SourceLongitude"
## [10] "TargetLatitude"  "TargetLongitude"
# Analysis of the Demographic channel:
glimpse(qt4_5)
## Observations: 494
## Variables: 11
## $ Source          <chr> "464579", "464579", "464579", "464579", "46457...
## $ eType           <int> 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5...
## $ Target          <chr> "536346", "567195", "527449", "459381", "59529...
## $ Time            <int> 31536000, 31536000, 31536000, 31536000, 315360...
## $ Weight          <dbl> 5352.39, 1900.95, 1574.64, 1363.77, 9000.70, 1...
## $ SourceLocation  <int> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
## $ TargetLocation  <int> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
## $ SourceLatitude  <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
## $ SourceLongitude <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
## $ TargetLatitude  <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
## $ TargetLongitude <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
#unique(qt4_5)
unique(qt4_5$eType) # 5
## [1] 5
unique(qt4_5$SourceLocation) # NA
## [1] NA
unique(qt4_5$TargetLocation) # NA
## [1] NA
unique(qt4_5$SourceLatitude) # NA
## [1] NA
unique(qt4_5$SourceLongitude) # NA
## [1] NA
unique(qt4_5$TargetLatitude) # NA
## [1] NA
unique(qt4_5$TargetLongitude) # NA
## [1] NA
unique(qt4_5$Source)
##  [1] "464579" "482012" "492850" "510031" "536906" "546593" "552988"
##  [8] "569329" "580798" "588172" "620120" "636721" "657526" "557269"
## [15] "655963" "639642" "585606" "571369" "516873" "566580" "477374"
## [22] "584457" "544636" "483005" "579305" "601496" "628320" "541907"
unique(qt4_5$Target)
##  [1] "536346" "567195" "527449" "459381" "595298" "466907" "577992"
##  [8] "537281" "523927" "595581" "642329" "503701" "571970" "644226"
## [15] "632961" "473173" "620120" "575030" "630626" "580426" "616315"
## [22] "520660" "589943" "569329" "588172" "492850" "636721" "580798"
## [29] "546593" "536906" "606730" "482012" "657526" "464579" "621924"
## [36] "503218" "557269" "640784" "655963" "639642" "585606" "571369"
## [43] "516873" "566580" "477374" "584457" "544636" "483005" "579305"
## [50] "601496" "628320" "541907"
unique(qt4_5$Weight)
##   [1]   5352.39   1900.95   1574.64   1363.77   9000.70   1294.57   1895.87
##   [8]    741.67   5666.86   1840.03   1267.62   7921.31    119.85   4204.22
##  [15]    950.28   1737.76   6540.04   5627.55   5124.17    283.45    369.53
##  [22]   1267.93    696.89    988.82    114.80    512.19    133.42    772.30
##  [29]    447.06   2688.40     41.22    100.20   3734.96   2516.93   6672.05
##  [36]   1243.11    500.25   1663.24     49.18    380.93   1598.86    355.75
##  [43]   2215.63    392.32    344.50    512.35     15.21   1845.50    136.34
##  [50]    734.04    311.58   1039.37  10152.60    498.36    450.54    630.62
##  [57]     32.96    792.79   1878.82    115.42   1844.96   1525.27    173.56
##  [64]    165.42    309.24    392.75    351.20    852.11   3283.68    278.73
##  [71]    166.04    724.28    334.44    158.92     97.12   9245.31   4241.32
##  [78]    667.15   1042.23   1011.45    679.18   4144.21   5961.09   1102.59
##  [85]   1259.95   1277.66   1527.56   6321.04   2378.14   1986.66   9478.52
##  [92]  18450.20   4410.78  19821.50  13157.70   8773.28   7720.52  37449.40
##  [99]   2614.97  20352.50    115.79   4210.97    775.94    615.23   3991.31
## [106]   1168.89   2970.54      2.39   1021.95    720.96    609.94   1790.61
## [113]   2061.71   2165.12   1452.84  14649.50    426.21    109.02     48.73
## [120]      4.44     21.11    146.95   1975.82    168.32     17.58    262.83
## [127]   1334.54    187.42   1514.53    993.98    713.31   4659.92   1670.19
## [134]    509.54    187.26    198.14    594.06    209.50    413.23     18.64
## [141]    706.54    331.34    177.90     14.11    188.27    119.39    661.16
## [148]    224.71    486.33   1502.52   1639.51    646.98    240.67    569.33
## [155]   1862.42    400.82   2841.47    433.38   1235.58    252.20   1518.22
## [162]    149.78     44.14    983.64    796.16    864.13    432.71   3697.33
## [169]   6893.61    102.03    649.81   1237.39    377.67   6387.94   1444.46
## [176]    896.12   2708.62    984.37    691.57   2152.02   1133.34    417.98
## [183]   7935.60    317.61    655.13    730.33    422.10     49.47    203.94
## [190]    603.25    103.21    114.05    121.83    478.86    226.22    326.47
## [197]   1070.35    517.84     85.76   1351.44   4724.30     35.87    296.85
## [204]  23697.10   7517.28    905.62   1515.98   7064.27   3416.10   4569.15
## [211]   4425.31   5185.15   3230.10   1483.75   3670.14    524.95   1960.36
## [218]   2511.28  15948.00  15436.20   3952.68   2502.66 109907.00    854.36
## [225]    907.20   3262.45    355.30    782.44    692.16    553.99    419.38
## [232]   1965.25    277.86   1346.99   1379.15   2033.67     75.20   1415.71
## [239]      8.34   1451.89   1983.78   3458.50    450.07    850.33  17549.40
## [246]    636.46   1624.18     25.63    705.58    979.70     56.59    531.78
## [253]    317.77    611.41   1133.39   1002.26     67.06    395.03     61.78
## [260]   1396.83    426.85   6110.68   4660.12    563.88   3906.88   1746.28
## [267]   4328.33    580.13   1403.61   6710.84   2069.84   1752.47   4033.83
## [274]   6237.13   2505.02  13236.00   1469.80   5371.76   1665.05   2302.65
## [281]  25968.10  39565.60   4412.93   7855.50 141744.00   1118.65   1367.23
## [288]    364.94    875.90   2110.77   1033.21   4952.46   4771.52    552.41
## [295]   9585.05   3966.64   3586.36   3838.17   2835.05   3068.77    314.77
## [302]   1459.69  97608.40  10798.30  31264.80  67163.20    132.44   1740.54
## [309]    103.70     81.43   1583.24     49.59   1649.44   2275.25   1188.57
## [316]    221.39    584.72    106.88   3687.20    788.91     19.13   3158.36
## [323]    146.83    715.96   1045.51    272.05    330.65    692.91     56.24
## [330]    191.21     34.71    897.96     24.56   1136.23    180.66   2295.07
## [337]     64.76    622.83    710.23   1198.06    333.32    272.08  13703.40
## [344]    383.60   1488.77   1088.44     61.59    301.58    137.73   2064.53
## [351]    111.43   1285.34     53.76     31.71    843.95   1347.57    123.98
## [358]    594.22    127.35    736.57   2645.89    326.38   4963.30    648.85
## [365]    826.90   6870.03  11603.10    157.01    408.08    781.41    585.10
## [372]   1345.64    482.61   1823.33    266.98   3506.07   1135.68   1866.86
## [379]     78.41     31.31    362.15   7595.77   1166.13    777.87  38582.00
## [386]    304.09    309.77    562.84    743.14    273.13    424.78   1796.07
## [393]    265.53   2077.39    339.53    147.51    576.65    138.96    578.05
## [400]    856.97    839.07    950.07    269.26   1337.98   3561.76   4521.72
## [407]    415.16   1610.81   2358.23    709.81    902.26   5024.56   1704.00
## [414]   2187.16    181.37   2968.37    756.21   4096.56   3014.60   3210.12
## [421]    271.10   3653.69    301.26     80.93    874.84  17251.30  14454.60
## [428]   1119.39  27376.10   4789.41    483.42    430.54    466.44    813.91
## [435]    513.06    400.64    875.81    468.27    111.51   1547.32    391.11
## [442]    331.23   1009.57    168.60   1997.14     66.41     47.31   1078.45
## [449]    206.88   1817.39   8395.12    198.72     48.44   1444.23    414.14
## [456]    162.71    284.91   1626.88    235.40    597.67    151.93    940.97
## [463]    430.79    964.22   1019.65    669.50   2076.09     64.94    422.27
## [470]    208.23    335.43    356.86   1687.09    369.59  10065.50   2670.87
## [477]   1097.67      3.66    195.12    733.14    206.59    332.15    461.43
## [484]    245.00    371.91    465.34    492.28    120.76    435.81    114.54
## [491]     43.82    357.94   7219.68      7.79
qt4_5 <- subset(qt4_5, select = -c(SourceLocation, TargetLocation, SourceLatitude, SourceLongitude, TargetLatitude, TargetLongitude)) # SOurce and Target Latitude and Longitude columns removed as all Null.
colnames(qt4_5)
## [1] "Source" "eType"  "Target" "Time"   "Weight"
range(qt4_5$Source) # 466976 657076
## [1] "464579" "657526"
range(qt4_5$Target) # 459381 657076
## [1] "459381" "657526"
range(qt4_5$Time) # 31536000-31536000
## [1] 31536000 31536000
income_cat_qt4 <- NULL
# Income Categories:
for (i in (qt4_5$Source)) {
  for (j in (cat$NodeID)) {                   # cat_list contains all the demographic nodeIDs (from the DemographicNodeExtraction Script)
    if(i == j){
      income_cat_qt4 <- append(income_cat_qt4,i)
    }
  }
}

print(income_cat_qt4) # income categories extracted
##  [1] "510031" "510031" "510031" "510031" "510031" "510031" "510031"
##  [8] "552988" "552988" "552988" "552988" "552988" "552988" "552988"
## [15] "552988" "552988" "552988" "620120" "620120" "552988" "620120"
## [22] "510031" "552988" "510031" "552988" "510031" "552988" "510031"
## [29] "552988" "552988" "510031" "552988" "552988" "510031" "552988"
## [36] "510031" "552988" "552988" "620120" "510031" "552988" "552988"
## [43] "510031" "552988" "510031" "552988" "620120"
unique(income_cat_qt4) # 3
## [1] "510031" "552988" "620120"
qt4_5_sub1 <- subset(qt4_5, qt4_5$Source == income_cat_qt4) # Subset of data with only income categories
## Warning in qt4_5$Source == income_cat_qt4: longer object length is not a
## multiple of shorter object length
str(qt4_5_sub1)
## 'data.frame':    16 obs. of  5 variables:
##  $ Source: chr  "510031" "552988" "552988" "552988" ...
##  $ eType : int  5 5 5 5 5 5 5 5 5 5 ...
##  $ Target: chr  "569329" "569329" "588172" "557269" ...
##  $ Time  : int  31536000 31536000 31536000 31536000 31536000 31536000 31536000 31536000 31536000 31536000 ...
##  $ Weight: num  498 9479 4411 4724 2503 ...
plot(qt4_5_sub1$Source, qt4_5_sub1$Weight) # Plot of Monetary income in each category

# Expense Categories:
expense_cat_qt4 <- NULL
for (k in qt4_5$Target) {
  for(l in cat$NodeID){ 
    if(k==l){
      expense_cat_qt4 <- append(expense_cat_qt4, k)
    }
  }
  
}
print(expense_cat_qt4) # expense categories extracted
##   [1] "536346" "567195" "527449" "459381" "595298" "466907" "577992"
##   [8] "537281" "523927" "595581" "642329" "503701" "571970" "644226"
##  [15] "632961" "473173" "620120" "575030" "630626" "527449" "459381"
##  [22] "595298" "466907" "577992" "537281" "580426" "595581" "616315"
##  [29] "642329" "503701" "571970" "632961" "473173" "620120" "575030"
##  [36] "536346" "520660" "567195" "527449" "459381" "595298" "466907"
##  [43] "589943" "537281" "523927" "580426" "595581" "503701" "571970"
##  [50] "644226" "473173" "620120" "575030" "630626" "567195" "527449"
##  [57] "459381" "595298" "466907" "606730" "589943" "577992" "537281"
##  [64] "616315" "642329" "632961" "473173" "620120" "630626" "567195"
##  [71] "527449" "459381" "595298" "466907" "589943" "577992" "537281"
##  [78] "580426" "595581" "642329" "503701" "473173" "620120" "536346"
##  [85] "567195" "527449" "459381" "595298" "466907" "577992" "523927"
##  [92] "580426" "595581" "616315" "503701" "644226" "473173" "620120"
##  [99] "575030" "536346" "567195" "527449" "459381" "595298" "466907"
## [106] "577992" "537281" "523927" "580426" "616315" "642329" "503701"
## [113] "644226" "473173" "575030" "630626" "567195" "527449" "459381"
## [120] "595298" "466907" "577992" "537281" "523927" "616315" "642329"
## [127] "571970" "632961" "473173" "620120" "621924" "630626" "567195"
## [134] "527449" "459381" "595298" "466907" "589943" "595581" "616315"
## [141] "642329" "503701" "571970" "632961" "473173" "621924" "503218"
## [148] "536346" "520660" "567195" "527449" "459381" "595298" "466907"
## [155] "589943" "577992" "537281" "580426" "595581" "616315" "503701"
## [162] "644226" "473173" "620120" "621924" "536346" "520660" "567195"
## [169] "527449" "459381" "595298" "466907" "606730" "537281" "523927"
## [176] "580426" "595581" "503701" "644226" "473173" "621924" "640784"
## [183] "630626" "567195" "527449" "459381" "595298" "466907" "589943"
## [190] "577992" "523927" "580426" "616315" "642329" "571970" "632961"
## [197] "473173" "620120" "575030" "621924" "536346" "520660" "567195"
## [204] "527449" "459381" "595298" "466907" "577992" "523927" "580426"
## [211] "595581" "642329" "503701" "571970" "644226" "632961" "473173"
## [218] "620120" "575030" "621924" "503218" "536346" "527449" "459381"
## [225] "595298" "466907" "589943" "537281" "595581" "616315" "503701"
## [232] "571970" "644226" "632961" "473173" "620120" "575030" "621924"
## [239] "640784" "536346" "527449" "459381" "595298" "466907" "577992"
## [246] "595581" "616315" "642329" "503701" "571970" "644226" "632961"
## [253] "473173" "620120" "575030" "621924" "640784" "536346" "527449"
## [260] "459381" "595298" "466907" "589943" "577992" "537281" "523927"
## [267] "580426" "616315" "642329" "503701" "644226" "632961" "473173"
## [274] "620120" "575030" "621924" "640784" "630626" "527449" "459381"
## [281] "595298" "466907" "577992" "523927" "616315" "632961" "473173"
## [288] "620120" "575030" "621924" "640784" "536346" "567195" "527449"
## [295] "459381" "595298" "466907" "589943" "537281" "523927" "580426"
## [302] "595581" "642329" "503701" "571970" "644226" "473173" "620120"
## [309] "575030" "621924" "640784" "536346" "567195" "527449" "459381"
## [316] "595298" "589943" "537281" "523927" "580426" "595581" "616315"
## [323] "503701" "571970" "644226" "473173" "620120" "575030" "640784"
## [330] "503218" "630626" "567195" "527449" "459381" "595298" "466907"
## [337] "577992" "537281" "523927" "580426" "595581" "616315" "503701"
## [344] "571970" "632961" "473173" "620120" "575030" "640784" "503218"
## [351] "536346" "567195" "527449" "459381" "595298" "466907" "577992"
## [358] "537281" "523927" "580426" "595581" "616315" "642329" "503701"
## [365] "644226" "473173" "575030" "621924" "536346" "567195" "527449"
## [372] "459381" "595298" "466907" "589943" "537281" "523927" "580426"
## [379] "595581" "616315" "642329" "571970" "644226" "632961" "473173"
## [386] "620120" "575030" "621924" "630626" "567195" "527449" "459381"
## [393] "595298" "466907" "606730" "589943" "577992" "537281" "523927"
## [400] "580426" "595581" "616315" "642329" "503701" "571970" "632961"
## [407] "473173" "620120" "575030" "640784" "536346" "520660" "567195"
## [414] "527449" "459381" "595298" "466907" "577992" "537281" "523927"
## [421] "580426" "595581" "616315" "642329" "503701" "571970" "644226"
## [428] "632961" "473173" "620120" "575030" "630626" "567195" "527449"
## [435] "459381" "595298" "466907" "606730" "589943" "537281" "580426"
## [442] "595581" "616315" "642329" "503701" "632961" "473173"
unique(expense_cat_qt4) # 27
##  [1] "536346" "567195" "527449" "459381" "595298" "466907" "577992"
##  [8] "537281" "523927" "595581" "642329" "503701" "571970" "644226"
## [15] "632961" "473173" "620120" "575030" "630626" "580426" "616315"
## [22] "520660" "589943" "606730" "621924" "503218" "640784"
qt4_5_sub2 <- subset(qt4_5, qt4_5$Target == expense_cat_qt4) # Subset of data with only expense categories
## Warning in qt4_5$Target == expense_cat_qt4: longer object length is not a
## multiple of shorter object length
str(qt4_5_sub2)
## 'data.frame':    66 obs. of  5 variables:
##  $ Source: chr  "464579" "464579" "464579" "464579" ...
##  $ eType : int  5 5 5 5 5 5 5 5 5 5 ...
##  $ Target: chr  "536346" "567195" "527449" "459381" ...
##  $ Time  : int  31536000 31536000 31536000 31536000 31536000 31536000 31536000 31536000 31536000 31536000 ...
##  $ Weight: num  5352 1901 1575 1364 9001 ...
plot(qt4_5_sub2$Target, qt4_5_sub2$Weight) # Plot of Monetary expenses in each category

hist(qt4_5$Weight)

unique(qt4_5$Weight)
##   [1]   5352.39   1900.95   1574.64   1363.77   9000.70   1294.57   1895.87
##   [8]    741.67   5666.86   1840.03   1267.62   7921.31    119.85   4204.22
##  [15]    950.28   1737.76   6540.04   5627.55   5124.17    283.45    369.53
##  [22]   1267.93    696.89    988.82    114.80    512.19    133.42    772.30
##  [29]    447.06   2688.40     41.22    100.20   3734.96   2516.93   6672.05
##  [36]   1243.11    500.25   1663.24     49.18    380.93   1598.86    355.75
##  [43]   2215.63    392.32    344.50    512.35     15.21   1845.50    136.34
##  [50]    734.04    311.58   1039.37  10152.60    498.36    450.54    630.62
##  [57]     32.96    792.79   1878.82    115.42   1844.96   1525.27    173.56
##  [64]    165.42    309.24    392.75    351.20    852.11   3283.68    278.73
##  [71]    166.04    724.28    334.44    158.92     97.12   9245.31   4241.32
##  [78]    667.15   1042.23   1011.45    679.18   4144.21   5961.09   1102.59
##  [85]   1259.95   1277.66   1527.56   6321.04   2378.14   1986.66   9478.52
##  [92]  18450.20   4410.78  19821.50  13157.70   8773.28   7720.52  37449.40
##  [99]   2614.97  20352.50    115.79   4210.97    775.94    615.23   3991.31
## [106]   1168.89   2970.54      2.39   1021.95    720.96    609.94   1790.61
## [113]   2061.71   2165.12   1452.84  14649.50    426.21    109.02     48.73
## [120]      4.44     21.11    146.95   1975.82    168.32     17.58    262.83
## [127]   1334.54    187.42   1514.53    993.98    713.31   4659.92   1670.19
## [134]    509.54    187.26    198.14    594.06    209.50    413.23     18.64
## [141]    706.54    331.34    177.90     14.11    188.27    119.39    661.16
## [148]    224.71    486.33   1502.52   1639.51    646.98    240.67    569.33
## [155]   1862.42    400.82   2841.47    433.38   1235.58    252.20   1518.22
## [162]    149.78     44.14    983.64    796.16    864.13    432.71   3697.33
## [169]   6893.61    102.03    649.81   1237.39    377.67   6387.94   1444.46
## [176]    896.12   2708.62    984.37    691.57   2152.02   1133.34    417.98
## [183]   7935.60    317.61    655.13    730.33    422.10     49.47    203.94
## [190]    603.25    103.21    114.05    121.83    478.86    226.22    326.47
## [197]   1070.35    517.84     85.76   1351.44   4724.30     35.87    296.85
## [204]  23697.10   7517.28    905.62   1515.98   7064.27   3416.10   4569.15
## [211]   4425.31   5185.15   3230.10   1483.75   3670.14    524.95   1960.36
## [218]   2511.28  15948.00  15436.20   3952.68   2502.66 109907.00    854.36
## [225]    907.20   3262.45    355.30    782.44    692.16    553.99    419.38
## [232]   1965.25    277.86   1346.99   1379.15   2033.67     75.20   1415.71
## [239]      8.34   1451.89   1983.78   3458.50    450.07    850.33  17549.40
## [246]    636.46   1624.18     25.63    705.58    979.70     56.59    531.78
## [253]    317.77    611.41   1133.39   1002.26     67.06    395.03     61.78
## [260]   1396.83    426.85   6110.68   4660.12    563.88   3906.88   1746.28
## [267]   4328.33    580.13   1403.61   6710.84   2069.84   1752.47   4033.83
## [274]   6237.13   2505.02  13236.00   1469.80   5371.76   1665.05   2302.65
## [281]  25968.10  39565.60   4412.93   7855.50 141744.00   1118.65   1367.23
## [288]    364.94    875.90   2110.77   1033.21   4952.46   4771.52    552.41
## [295]   9585.05   3966.64   3586.36   3838.17   2835.05   3068.77    314.77
## [302]   1459.69  97608.40  10798.30  31264.80  67163.20    132.44   1740.54
## [309]    103.70     81.43   1583.24     49.59   1649.44   2275.25   1188.57
## [316]    221.39    584.72    106.88   3687.20    788.91     19.13   3158.36
## [323]    146.83    715.96   1045.51    272.05    330.65    692.91     56.24
## [330]    191.21     34.71    897.96     24.56   1136.23    180.66   2295.07
## [337]     64.76    622.83    710.23   1198.06    333.32    272.08  13703.40
## [344]    383.60   1488.77   1088.44     61.59    301.58    137.73   2064.53
## [351]    111.43   1285.34     53.76     31.71    843.95   1347.57    123.98
## [358]    594.22    127.35    736.57   2645.89    326.38   4963.30    648.85
## [365]    826.90   6870.03  11603.10    157.01    408.08    781.41    585.10
## [372]   1345.64    482.61   1823.33    266.98   3506.07   1135.68   1866.86
## [379]     78.41     31.31    362.15   7595.77   1166.13    777.87  38582.00
## [386]    304.09    309.77    562.84    743.14    273.13    424.78   1796.07
## [393]    265.53   2077.39    339.53    147.51    576.65    138.96    578.05
## [400]    856.97    839.07    950.07    269.26   1337.98   3561.76   4521.72
## [407]    415.16   1610.81   2358.23    709.81    902.26   5024.56   1704.00
## [414]   2187.16    181.37   2968.37    756.21   4096.56   3014.60   3210.12
## [421]    271.10   3653.69    301.26     80.93    874.84  17251.30  14454.60
## [428]   1119.39  27376.10   4789.41    483.42    430.54    466.44    813.91
## [435]    513.06    400.64    875.81    468.27    111.51   1547.32    391.11
## [442]    331.23   1009.57    168.60   1997.14     66.41     47.31   1078.45
## [449]    206.88   1817.39   8395.12    198.72     48.44   1444.23    414.14
## [456]    162.71    284.91   1626.88    235.40    597.67    151.93    940.97
## [463]    430.79    964.22   1019.65    669.50   2076.09     64.94    422.27
## [470]    208.23    335.43    356.86   1687.09    369.59  10065.50   2670.87
## [477]   1097.67      3.66    195.12    733.14    206.59    332.15    461.43
## [484]    245.00    371.91    465.34    492.28    120.76    435.81    114.54
## [491]     43.82    357.94   7219.68      7.79
range(qt4_5$Weight) #2.39 141744.00
## [1]      2.39 141744.00
# To-do : normalise the weights to better visualise in graph. Convert to csv maybe.

Graph 5 Analysis:

# Load The Data:
qt5 <- data.table::fread(here::here("data", "Q1-Graph5.csv"))
head(qt5)
##    Source eType Target   Time Weight SourceLocation TargetLocation
## 1: 619322     3 590442  96346     17             NA             NA
## 2: 594308     0 549840 105656      1             NA             NA
## 3: 524153     3 629769 307922      4             NA             NA
## 4: 524153     3 461577 449990   1923             NA             NA
## 5: 619322     3 547205 634562    242             NA             NA
## 6: 483784     0 631903 975525      1             NA             NA
##    SourceLatitude SourceLongitude TargetLatitude TargetLongitude
## 1:             NA              NA             NA              NA
## 2:             NA              NA             NA              NA
## 3:             NA              NA             NA              NA
## 4:             NA              NA             NA              NA
## 5:             NA              NA             NA              NA
## 6:             NA              NA             NA              NA
tail(qt5)
##    Source eType Target     Time   Weight SourceLocation TargetLocation
## 1: 573137     5 632961 31536000   297.91             NA             NA
## 2: 573137     5 473173 31536000   248.56             NA             NA
## 3: 573137     5 620120 31536000  1295.19             NA             NA
## 4: 573137     5 575030 31536000  4835.03             NA             NA
## 5: 573137     5 621924 31536000   328.93             NA             NA
## 6: 552988     5 573137 31536000 11488.30             NA             NA
##    SourceLatitude SourceLongitude TargetLatitude TargetLongitude
## 1:             NA              NA             NA              NA
## 2:             NA              NA             NA              NA
## 3:             NA              NA             NA              NA
## 4:             NA              NA             NA              NA
## 5:             NA              NA             NA              NA
## 6:             NA              NA             NA              NA
# Summarising the Data:
summary(qt5)
##      Source           eType           Target            Time         
##  Min.   :477657   Min.   :0.000   Min.   :459381   Min.   :   96346  
##  1st Qu.:510031   1st Qu.:5.000   1st Qu.:523927   1st Qu.:14947200  
##  Median :552988   Median :5.000   Median :567195   Median :31536000  
##  Mean   :553140   Mean   :4.635   Mean   :566074   Mean   :23453574  
##  3rd Qu.:594308   3rd Qu.:6.000   3rd Qu.:616453   3rd Qu.:31536000  
##  Max.   :631903   Max.   :6.000   Max.   :657173   Max.   :31536000  
##                                                                      
##      Weight         SourceLocation  TargetLocation  SourceLatitude   
##  Min.   :    -1.0   Min.   :0.000   Min.   :0.000   Min.   :-29.000  
##  1st Qu.:     1.0   1st Qu.:2.000   1st Qu.:1.000   1st Qu.:-25.000  
##  Median :   198.0   Median :2.500   Median :3.000   Median :-22.000  
##  Mean   :  2758.5   Mean   :2.355   Mean   :2.718   Mean   : -6.987  
##  3rd Qu.:   983.4   3rd Qu.:3.000   3rd Qu.:5.000   3rd Qu.:  1.000  
##  Max.   :441206.0   Max.   :5.000   Max.   :5.000   Max.   : 33.000  
##                     NA's   :271     NA's   :271     NA's   :271      
##  SourceLongitude   TargetLatitude    TargetLongitude  
##  Min.   :-170.65   Min.   :-29.000   Min.   :-170.65  
##  1st Qu.:-111.00   1st Qu.:-22.000   1st Qu.:-111.00  
##  Median : -41.00   Median : 22.000   Median : -41.00  
##  Mean   : -37.91   Mean   :  6.702   Mean   : -13.75  
##  3rd Qu.:  91.00   3rd Qu.: 23.281   3rd Qu.: 152.20  
##  Max.   : 156.00   Max.   : 33.000   Max.   : 156.00  
##  NA's   :271       NA's   :271       NA's   :271
nrow(qt5) #395
## [1] 395
ncol(qt5) #11
## [1] 11
qt5$Source <- as.character(qt5$Source)
qt5$Target <- as.character(qt5$Target)

# Differentiating between channels:
qt5_01 <- qt5 %>% filter(qt5$eType == 0 | qt5$eType == 1) # Communication Channel
nrow(qt5_01) # 31
## [1] 31
qt5_23 <- qt5 %>% filter(qt5$eType == 2 | qt5$eType == 3) # Procurement Channel
nrow(qt5_23) # 51
## [1] 51
qt5_4 <- qt5 %>% filter(qt5$eType == 4) # Co-authorship Channel
nrow(qt5_4) # 0
## [1] 0
qt5_5 <- qt5 %>% filter(qt5$eType == 5) # Demographic Channel
nrow(qt5_5) # 203
## [1] 203
qt5_6 <- qt5 %>% filter(qt5$eType == 6) # Travel Channel
nrow(qt5_6) # 110
## [1] 110
# Highest data for Demographic, Travel Channel and Procurement.

# Analysis of the Communication channel:
glimpse(qt5_01)
## Observations: 31
## Variables: 11
## $ Source          <chr> "594308", "483784", "549840", "594308", "48378...
## $ eType           <int> 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0...
## $ Target          <chr> "549840", "631903", "619322", "477657", "61932...
## $ Time            <int> 105656, 975525, 1674004, 2053209, 4699152, 792...
## $ Weight          <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1...
## $ SourceLocation  <int> NA, NA, NA, 2, 0, 0, 4, 3, 2, 0, NA, NA, 4, NA...
## $ TargetLocation  <int> NA, NA, NA, 4, 3, 1, 1, 3, 5, 5, NA, NA, 3, NA...
## $ SourceLatitude  <dbl> NA, NA, NA, -24.176100, 32.250300, 32.250300, ...
## $ SourceLongitude <dbl> NA, NA, NA, 93.8902, -40.4067, -40.4067, -170....
## $ TargetLatitude  <dbl> NA, NA, NA, -1.17279, -24.22860, -27.47660, -2...
## $ TargetLongitude <dbl> NA, NA, NA, -170.6460, -111.1290, -14.6148, -1...
#unique(qt5_01)
unique(qt5_01$eType) # 0 1
## [1] 0 1
unique(qt5_01$SourceLocation) # NA  2  0  4  3
## [1] NA  2  0  4  3
unique(qt5_01$TargetLocation) # NA  4  3  1  5
## [1] NA  4  3  1  5
unique(qt5_01$SourceLatitude) 
## [1]         NA -24.176100  32.250300  -1.172790 -24.228600   0.259451
## [7] -25.031300
unique(qt5_01$SourceLongitude)
## [1]        NA   93.8902  -40.4067 -170.6460 -111.1290 -165.5760 -110.7380
unique(qt5_01$TargetLatitude) 
## [1]        NA  -1.17279 -24.22860 -27.47660 -25.03130  25.55350  22.52320
unique(qt5_01$TargetLongitude) 
## [1]        NA -170.6460 -111.1290  -14.6148 -110.7380  153.2350  151.8550
unique(qt5_01$Source) 
##  [1] "594308" "483784" "549840" "477657" "619322" "524153" "573137"
##  [8] "530990" "631903" "561819"
unique(qt5_01$Target) 
## [1] "549840" "631903" "619322" "477657" "561819" "530990" "594308" "524153"
## [9] "573137"
colnames(qt5_01)
##  [1] "Source"          "eType"           "Target"         
##  [4] "Time"            "Weight"          "SourceLocation" 
##  [7] "TargetLocation"  "SourceLatitude"  "SourceLongitude"
## [10] "TargetLatitude"  "TargetLongitude"
# Analysis of the Demographic channel:
glimpse(qt5_5)
## Observations: 203
## Variables: 11
## $ Source          <chr> "483784", "483784", "483784", "483784", "48378...
## $ eType           <int> 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5...
## $ Target          <chr> "503218", "536346", "520660", "567195", "52744...
## $ Time            <int> 31536000, 31536000, 31536000, 31536000, 315360...
## $ Weight          <dbl> 5148.59, 12802.80, 31733.80, 29938.60, 983.85,...
## $ SourceLocation  <int> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
## $ TargetLocation  <int> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
## $ SourceLatitude  <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
## $ SourceLongitude <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
## $ TargetLatitude  <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
## $ TargetLongitude <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
#unique(qt5_5)
unique(qt5_5$eType) # 5
## [1] 5
unique(qt5_5$SourceLocation) # NA
## [1] NA
unique(qt5_5$TargetLocation) # NA
## [1] NA
unique(qt5_5$SourceLatitude) # NA
## [1] NA
unique(qt5_5$SourceLongitude) # NA
## [1] NA
unique(qt5_5$TargetLatitude) # NA
## [1] NA
unique(qt5_5$TargetLongitude) # NA
## [1] NA
unique(qt5_5$Source)
##  [1] "483784" "510031" "552988" "620120" "561819" "530990" "619322"
##  [8] "631903" "524153" "549840" "477657" "594308" "573137"
unique(qt5_5$Target)
##  [1] "503218" "536346" "520660" "567195" "527449" "459381" "595298"
##  [8] "466907" "589943" "577992" "537281" "523927" "580426" "595581"
## [15] "616315" "642329" "503701" "571970" "644226" "632961" "473173"
## [22] "483784" "620120" "575030" "621924" "561819" "640784" "530990"
## [29] "619322" "630626" "606730" "631903" "524153" "549840" "477657"
## [36] "594308" "573137"
unique(qt5_5$Weight)
##   [1]   5148.59  12802.80  31733.80  29938.60    983.85   1728.16   6120.39
##   [8]   2657.09  10303.10  18663.50   1956.93   5330.29  18354.90   8666.52
##  [15]  36827.80   8277.90  17303.80   1340.05   7333.98   2588.25    572.69
##  [22]   1201.05 441206.00   2356.79    729.34   1268.58    109.98     61.95
##  [29]    699.05    303.21    541.51    366.28   1011.27    922.76    982.87
##  [36]    418.66    421.73    661.68   1027.12    262.73   2435.24    460.37
##  [43]   2497.95    417.69  11074.40    130.95   1109.22   3451.82    267.97
##  [50]    216.43   2126.40     29.42   2583.05    390.48    749.67    612.18
##  [57]    797.33   2692.27    134.41     62.83    590.84   3139.99   7510.12
##  [64]    325.81  21534.10    444.76   1982.88   4452.55     62.80    379.61
##  [71]   1133.88    655.16     83.88    235.34    534.96    521.92   1411.22
##  [78]   1183.04    253.08    112.12    302.50    248.96   1504.41   5634.90
##  [85]    712.17  25157.90    310.16   3654.46    236.72    205.47   1661.68
##  [92]    794.81    268.99   1605.74    717.54   2819.24    529.93    355.59
##  [99]   2988.87     62.49    822.66   3515.59   5123.35  23118.10    229.28
## [106]   3631.34   1348.59   1171.36   7740.68    143.57   4739.40    315.31
## [113]    507.95   3609.81    930.86   6028.10     11.03   2189.28     21.71
## [120]   1807.45  17503.10   3196.25   4561.47  23069.80    205.38    713.73
## [127]   2024.76    223.53    574.87    195.71    386.66   1291.33   2987.84
## [134]    392.46    345.49    216.70   2683.20    643.26    273.58   1676.57
## [141]    653.86   4156.52    248.04    762.06  10144.00    101.86   1164.18
## [148]    118.60    116.35    146.31    718.46    252.01    565.75    302.61
## [155]    581.82    513.34      0.17    437.04    162.53   2123.92    392.38
## [162]   3562.94   2416.01   2240.53   3651.56    487.49    298.61     81.19
## [169]    632.36     71.01   2959.18    247.67   3002.98   2958.78    571.12
## [176]   1019.14    974.96    284.64    657.17   3468.46   6971.99    190.00
## [183]   1693.86  33720.80    581.83    254.74   1357.29     45.68    210.35
## [190]   1725.25    322.40   2555.90     83.46    426.33     53.93    625.06
## [197]   1210.40    297.91    248.56   1295.19   4835.03    328.93  11488.30
qt5_5 <- subset(qt5_5, select = -c(SourceLocation, TargetLocation, SourceLatitude, SourceLongitude, TargetLatitude, TargetLongitude)) # SOurce and Target Latitude and Longitude columns removed as all Null.
colnames(qt5_5)
## [1] "Source" "eType"  "Target" "Time"   "Weight"
range(qt5_5$Source) # 466976 657076
## [1] "477657" "631903"
range(qt5_5$Target) # 459381 657076
## [1] "459381" "644226"
range(qt5_5$Time) # 31536000-31536000
## [1] 31536000 31536000
income_cat_qt5 <- NULL
# Income Categories:
for (i in (qt5_5$Source)) {
  for (j in (cat$NodeID)) {                   # cat_list contains all the demographic nodeIDs (from the DemographicNodeExtraction Script)
    if(i == j){
      income_cat_qt5 <- append(income_cat_qt5,i)
    }
  }
}

print(income_cat_qt5) # income categories extracted
##  [1] "510031" "552988" "620120" "552988" "510031" "552988" "552988"
##  [8] "552988" "510031" "552988" "510031" "552988" "510031" "552988"
## [15] "510031" "552988" "552988"
unique(income_cat_qt5) # 3
## [1] "510031" "552988" "620120"
qt5_5_sub1 <- subset(qt5_5, qt5_5$Source == income_cat_qt5) # Subset of data with only income categories
## Warning in qt5_5$Source == income_cat_qt5: longer object length is not a
## multiple of shorter object length
str(qt5_5_sub1)
## 'data.frame':    8 obs. of  5 variables:
##  $ Source: chr  "510031" "552988" "510031" "552988" ...
##  $ eType : int  5 5 5 5 5 5 5 5
##  $ Target: chr  "483784" "483784" "530990" "530990" ...
##  $ Time  : int  31536000 31536000 31536000 31536000 31536000 31536000 31536000 31536000
##  $ Weight: num  1201 441206 326 21534 23118 ...
plot(qt5_5_sub1$Source, qt5_5_sub1$Weight) # Plot of Monetary income in each category

# Expense Categories:
expense_cat_qt5 <- NULL
for (k in qt5_5$Target) {
  for(l in cat$NodeID){ 
    if(k==l){
      expense_cat_qt5 <- append(expense_cat_qt5, k)
    }
  }
  
}
print(expense_cat_qt5) # expense categories extracted
##   [1] "503218" "536346" "520660" "567195" "527449" "459381" "595298"
##   [8] "466907" "589943" "577992" "537281" "523927" "580426" "595581"
##  [15] "616315" "642329" "503701" "571970" "644226" "632961" "473173"
##  [22] "536346" "567195" "527449" "459381" "595298" "466907" "589943"
##  [29] "577992" "537281" "523927" "595581" "616315" "642329" "503701"
##  [36] "644226" "632961" "473173" "620120" "575030" "621924" "640784"
##  [43] "536346" "567195" "527449" "459381" "595298" "466907" "589943"
##  [50] "537281" "580426" "595581" "616315" "503701" "644226" "632961"
##  [57] "473173" "620120" "575030" "640784" "536346" "567195" "527449"
##  [64] "459381" "595298" "466907" "577992" "537281" "580426" "595581"
##  [71] "616315" "642329" "503701" "571970" "644226" "632961" "473173"
##  [78] "620120" "621924" "640784" "630626" "527449" "459381" "595298"
##  [85] "466907" "606730" "589943" "537281" "523927" "580426" "595581"
##  [92] "503701" "571970" "473173" "620120" "575030" "640784" "536346"
##  [99] "527449" "459381" "595298" "466907" "589943" "537281" "595581"
## [106] "616315" "642329" "503701" "571970" "644226" "473173" "620120"
## [113] "575030" "621924" "640784" "536346" "567195" "527449" "459381"
## [120] "595298" "466907" "589943" "577992" "537281" "523927" "616315"
## [127] "503701" "644226" "632961" "473173" "620120" "575030" "621924"
## [134] "640784" "630626" "567195" "527449" "459381" "595298" "466907"
## [141] "589943" "595581" "616315" "503701" "571970" "473173" "620120"
## [148] "575030" "536346" "520660" "567195" "527449" "459381" "595298"
## [155] "466907" "589943" "523927" "580426" "595581" "616315" "642329"
## [162] "503701" "644226" "632961" "473173" "620120" "575030" "621924"
## [169] "640784" "630626" "567195" "527449" "459381" "595298" "466907"
## [176] "589943" "577992" "537281" "580426" "595581" "503701" "632961"
## [183] "473173" "620120" "575030" "621924"
unique(expense_cat_qt5) # 27
##  [1] "503218" "536346" "520660" "567195" "527449" "459381" "595298"
##  [8] "466907" "589943" "577992" "537281" "523927" "580426" "595581"
## [15] "616315" "642329" "503701" "571970" "644226" "632961" "473173"
## [22] "620120" "575030" "621924" "640784" "630626" "606730"
qt5_5_sub2 <- subset(qt5_5, qt5_5$Target == expense_cat_qt5) # Subset of data with only expense categories
## Warning in qt5_5$Target == expense_cat_qt5: longer object length is not a
## multiple of shorter object length
str(qt5_5_sub2)
## 'data.frame':    21 obs. of  5 variables:
##  $ Source: chr  "483784" "483784" "483784" "483784" ...
##  $ eType : int  5 5 5 5 5 5 5 5 5 5 ...
##  $ Target: chr  "503218" "536346" "520660" "567195" ...
##  $ Time  : int  31536000 31536000 31536000 31536000 31536000 31536000 31536000 31536000 31536000 31536000 ...
##  $ Weight: num  5149 12803 31734 29939 984 ...
plot(qt5_5_sub2$Target, qt5_5_sub2$Weight) # Plot of Monetary expenses in each category

hist(qt5_5$Weight)

unique(qt5_5$Weight)
##   [1]   5148.59  12802.80  31733.80  29938.60    983.85   1728.16   6120.39
##   [8]   2657.09  10303.10  18663.50   1956.93   5330.29  18354.90   8666.52
##  [15]  36827.80   8277.90  17303.80   1340.05   7333.98   2588.25    572.69
##  [22]   1201.05 441206.00   2356.79    729.34   1268.58    109.98     61.95
##  [29]    699.05    303.21    541.51    366.28   1011.27    922.76    982.87
##  [36]    418.66    421.73    661.68   1027.12    262.73   2435.24    460.37
##  [43]   2497.95    417.69  11074.40    130.95   1109.22   3451.82    267.97
##  [50]    216.43   2126.40     29.42   2583.05    390.48    749.67    612.18
##  [57]    797.33   2692.27    134.41     62.83    590.84   3139.99   7510.12
##  [64]    325.81  21534.10    444.76   1982.88   4452.55     62.80    379.61
##  [71]   1133.88    655.16     83.88    235.34    534.96    521.92   1411.22
##  [78]   1183.04    253.08    112.12    302.50    248.96   1504.41   5634.90
##  [85]    712.17  25157.90    310.16   3654.46    236.72    205.47   1661.68
##  [92]    794.81    268.99   1605.74    717.54   2819.24    529.93    355.59
##  [99]   2988.87     62.49    822.66   3515.59   5123.35  23118.10    229.28
## [106]   3631.34   1348.59   1171.36   7740.68    143.57   4739.40    315.31
## [113]    507.95   3609.81    930.86   6028.10     11.03   2189.28     21.71
## [120]   1807.45  17503.10   3196.25   4561.47  23069.80    205.38    713.73
## [127]   2024.76    223.53    574.87    195.71    386.66   1291.33   2987.84
## [134]    392.46    345.49    216.70   2683.20    643.26    273.58   1676.57
## [141]    653.86   4156.52    248.04    762.06  10144.00    101.86   1164.18
## [148]    118.60    116.35    146.31    718.46    252.01    565.75    302.61
## [155]    581.82    513.34      0.17    437.04    162.53   2123.92    392.38
## [162]   3562.94   2416.01   2240.53   3651.56    487.49    298.61     81.19
## [169]    632.36     71.01   2959.18    247.67   3002.98   2958.78    571.12
## [176]   1019.14    974.96    284.64    657.17   3468.46   6971.99    190.00
## [183]   1693.86  33720.80    581.83    254.74   1357.29     45.68    210.35
## [190]   1725.25    322.40   2555.90     83.46    426.33     53.93    625.06
## [197]   1210.40    297.91    248.56   1295.19   4835.03    328.93  11488.30
range(qt5_5$Weight) #0.17 441206.00
## [1]      0.17 441206.00
# To-do : normalise the weights to better visualise in graph. Convert to csv maybe.

Parallel Coordinates for Template and Graph Data:

colnames(dt)
##  [1] "Source"          "eType"           "Target"         
##  [4] "Time"            "Weight"          "SourceLocation" 
##  [7] "TargetLocation"  "SourceLatitude"  "SourceLongitude"
## [10] "TargetLatitude"  "TargetLongitude"
ggparcoord(dt, columns = c(1,3,4,5), groupColumn = 4) # Parallel Coords for the Template

ggparcoord(qt1, columns = c(1,3,4,5), groupColumn = 4) # Parallel Coords for Graph 1

ggparcoord(qt2, columns = c(1,3,4,5), groupColumn = 4) # Parallel Coords for Graph 2

ggparcoord(qt3, columns = c(1,3,4,5), groupColumn = 4) # Parallel Coords for Graph 3

ggparcoord(qt4, columns = c(1,3,4,5), groupColumn = 4) # Parallel Coords for Graph 4

ggparcoord(qt5, columns = c(1,3,4,5), groupColumn = 4) # Parallel Coords for Graph 5

Communication Channel:

com_temp <- ggparcoord(dt01,columns = c(1,3,4,5), groupColumn = 4)
com_g1<- ggparcoord(qt1_01,columns = c(1,3,4,5), groupColumn = 4)
com_g2 <- ggparcoord(qt2_01,columns = c(1,3,4,5), groupColumn = 4)
com_g3 <- ggparcoord(qt3_01,columns = c(1,3,4,5), groupColumn = 4)
com_g4 <- ggparcoord(qt4_01,columns = c(1,3,4,5), groupColumn = 4)
com_g5 <- ggparcoord(qt5_01,columns = c(1,3,4,5), groupColumn = 4)
ggarrange(com_temp, com_g1, labels = c("Template", "Graph 1"), hjust = 0, vjust = 1, font.label = list(size = 10, color = "blue"))

ggarrange(com_temp, com_g2, labels = c("Template", "Graph 2"), hjust = 0, vjust = 1, font.label = list(size = 10, color = "blue"))

ggarrange(com_temp, com_g3, labels = c("Template", "Graph 3"), hjust = 0, vjust = 1, font.label = list(size = 10, color = "blue"))

ggarrange(com_temp, com_g4, labels = c("Template", "Graph 4"), hjust = 0, vjust = 1, font.label = list(size = 10, color = "blue"))

ggarrange(com_temp, com_g5, labels = c("Template", "Graph 5"), hjust = 0, vjust = 1, font.label = list(size = 10, color = "blue"))

Demographic Channel:

dem_temp <- ggparcoord(dt5, columns = c(1,3,4,5),groupColumn = 4)
dem_g1<- ggparcoord(qt1_5,columns = c(1,3,4,5), groupColumn = 4)
dem_g2 <- ggparcoord(qt2_5,columns = c(1,3,4,5), groupColumn = 4)
dem_g3 <- ggparcoord(qt3_5,columns = c(1,3,4,5), groupColumn = 4)
dem_g4 <- ggparcoord(qt4_5,columns = c(1,3,4,5), groupColumn = 4)
dem_g5 <- ggparcoord(qt5_5,columns = c(1,3,4,5), groupColumn = 4)
ggarrange(dem_temp, dem_g1, labels = c("Template", "Graph 1"), hjust = 0, vjust = 1, font.label = list(size = 10, color = "blue"))

ggarrange(dem_temp, dem_g2, labels = c("Template", "Graph 2"), hjust = 0, vjust = 1, font.label = list(size = 10, color = "blue"))

ggarrange(dem_temp, dem_g3, labels = c("Template", "Graph 3"), hjust = 0, vjust = 1, font.label = list(size = 10, color = "blue"))

ggarrange(dem_temp, dem_g4, labels = c("Template", "Graph 4"), hjust = 0, vjust = 1, font.label = list(size = 10, color = "blue"))

ggarrange(dem_temp, dem_g5, labels = c("Template", "Graph 5"), hjust = 0, vjust = 1, font.label = list(size = 10, color = "blue"))

Travel Channel:

tra_temp <- ggparcoord(dt6, columns = c(1,3,4,5),groupColumn = 4)
tra_g1<- ggparcoord(qt1_6,columns = c(1,3,4,5),groupColumn = 4)
tra_g2<- ggparcoord(qt2_6,columns = c(1,3,4,5),groupColumn = 4)
tra_g3<- ggparcoord(qt3_6,columns = c(1,3,4,5),groupColumn = 4)
tra_g4<- ggparcoord(qt4_6,columns = c(1,3,4,5),groupColumn = 4)
tra_g5<- ggparcoord(qt5_6,columns = c(1,3,4,5),groupColumn = 4)
ggarrange(tra_temp, tra_g1, labels = c("Template", "Graph 1"), hjust = 0, vjust = 1, font.label = list(size = 10, color = "blue"))

ggarrange(tra_temp, tra_g2, labels = c("Template", "Graph 2"), hjust = 0, vjust = 1, font.label = list(size = 10, color = "blue"))

ggarrange(tra_temp, tra_g3, labels = c("Template", "Graph 3"), hjust = 0, vjust = 1, font.label = list(size = 10, color = "blue"))

ggarrange(tra_temp, tra_g4, labels = c("Template", "Graph 4"), hjust = 0, vjust = 1, font.label = list(size = 10, color = "blue"))

ggarrange(tra_temp, tra_g5, labels = c("Template", "Graph 5"), hjust = 0, vjust = 1, font.label = list(size = 10, color = "blue"))

Procurement Channel:

pro_temp <- ggparcoord(dt23, columns = c(1,3,4,5),groupColumn = 4,scale = "center")
pro_g1<- ggparcoord(qt1_23,columns = c(1,3,4,5), groupColumn = 4, scale = "center")
pro_g2 <- ggparcoord(qt2_23,columns = c(1,3,4,5), groupColumn = 4,scale = "center")
pro_g3 <- ggparcoord(qt3_23,columns = c(1,3,4,5), groupColumn = 4,scale = "center")
pro_g4 <- ggparcoord(qt4_23,columns = c(1,3,4,5), groupColumn = 4,scale = "center")
pro_g5 <- ggparcoord(qt5_23,columns = c(1,3,4,5), groupColumn = 4,scale = "center")
ggarrange(pro_temp, pro_g1, labels = c("Template", "Graph 1"), hjust = 0, vjust = 1, font.label = list(size = 10, color = "blue"))

ggarrange(pro_temp, pro_g2, labels = c("Template", "Graph 2"), hjust = 0, vjust = 1, font.label = list(size = 10, color = "blue"))

ggarrange(pro_temp, pro_g3, labels = c("Template", "Graph 3"), hjust = 0, vjust = 1, font.label = list(size = 10, color = "blue"))

ggarrange(pro_temp, pro_g4, labels = c("Template", "Graph 4"), hjust = 0, vjust = 1, font.label = list(size = 10, color = "blue"))

ggarrange(pro_temp, pro_g5, labels = c("Template", "Graph 5"), hjust = 0, vjust = 1, font.label = list(size = 10, color = "blue"))

Removing Source and Target:

temp_1 <- ggparcoord(data = c(dt23), columns = c(4,5),groupColumn = 4 )
qt_1 <- ggparcoord(data = c(qt1_23), columns = c(4,5),groupColumn = 4 )
qt_2 <- ggparcoord(data = c(qt2_23), columns = c(4,5),groupColumn = 4 )
qt_3 <- ggparcoord(data = c(qt3_23), columns = c(4,5),groupColumn = 4 )
qt_4 <- ggparcoord(data = c(qt4_23), columns = c(4,5),groupColumn = 4 )
qt_5 <- ggparcoord(data = c(qt5_23), columns = c(4,5),groupColumn = 4 )
ggarrange(temp_1,qt_1,labels = c("Template", "Graph 1"), hjust = 0, vjust = 1, font.label = list(size = 10, color = "blue"))

ggarrange(temp_1,qt_2,labels = c("Template", "Graph 2"), hjust = 0, vjust = 1, font.label = list(size = 10, color = "blue"))

ggarrange(temp_1,qt_3,labels = c("Template", "Graph 3"), hjust = 0, vjust = 1, font.label = list(size = 10, color = "blue"))

ggarrange(temp_1,qt_4,labels = c("Template", "Graph 4"), hjust = 0, vjust = 1, font.label = list(size = 10, color = "blue"))

ggarrange(temp_1,qt_5,labels = c("Template", "Graph 5"), hjust = 0, vjust = 1, font.label = list(size = 10, color = "blue"))

Network Analysis:

# Communication Channel:
# For Template:
Sources <- dt01 %>%
  distinct(Source) %>%
  rename(label = Source)

Targets <- dt01 %>%
  distinct(Target) %>%
  rename(label = Target)

# Creating a Node List:
nodes <- full_join(Sources, Targets, by = "label")
nodes
##    label
## 1     41
## 2     37
## 3     34
## 4     27
## 5     40
## 6     65
## 7     67
## 8     47
## 9     39
## 10    43
## 11    57
## 12    58
## 13    63
## 14    56
## 15    45
## 16     0
## 17    66
nodes <- nodes %>% rowid_to_column("id")
nodes
##    id label
## 1   1    41
## 2   2    37
## 3   3    34
## 4   4    27
## 5   5    40
## 6   6    65
## 7   7    67
## 8   8    47
## 9   9    39
## 10 10    43
## 11 11    57
## 12 12    58
## 13 13    63
## 14 14    56
## 15 15    45
## 16 16     0
## 17 17    66
# Creating an Edge List:
per_route <- dt01 %>%  
  group_by(Source, Target) %>%
  summarise(weight = n()) %>% 
  ungroup()
per_route
## # A tibble: 113 x 3
##    Source Target weight
##    <chr>  <chr>   <int>
##  1 27     34          8
##  2 27     37         12
##  3 27     41          9
##  4 27     43          2
##  5 27     45          1
##  6 27     47          2
##  7 27     56          2
##  8 27     57          1
##  9 27     58          2
## 10 34     27         11
## # ... with 103 more rows
edges <- per_route %>% 
  left_join(nodes, by = c("Source" = "label")) %>% 
  rename(from = id)

edges <- edges %>% 
  left_join(nodes, by = c("Target" = "label")) %>% 
  rename(to = id)

edges <- select(edges, from, to, weight)
edges
## # A tibble: 113 x 3
##     from    to weight
##    <int> <int>  <int>
##  1     4     3      8
##  2     4     2     12
##  3     4     1      9
##  4     4    10      2
##  5     4    15      1
##  6     4     8      2
##  7     4    14      2
##  8     4    11      1
##  9     4    12      2
## 10     3     4     11
## # ... with 103 more rows
# Creating a Network:
routes_network <- network(edges, vertex.attr = nodes, matrix.type = "edgelist", ignore.eval = FALSE)
class(routes_network)
## [1] "network"
routes_network
##  Network attributes:
##   vertices = 17 
##   directed = TRUE 
##   hyper = FALSE 
##   loops = FALSE 
##   multiple = FALSE 
##   bipartite = FALSE 
##   total edges= 113 
##     missing edges= 0 
##     non-missing edges= 113 
## 
##  Vertex attribute names: 
##     id label vertex.names 
## 
##  Edge attribute names: 
##     weight
# Graph 1:
Sources_G1 <- qt1 %>%
  distinct(Source) %>%
  rename(label = Source)

Targets_G1 <- qt1 %>%
  distinct(Target) %>%
  rename(label = Target)

# Creating a Node List:
nodes_G1 <- full_join(Sources_G1, Targets_G1, by = "label")
nodes_G1
##     label
## 1  616050
## 2  599956
## 3  490041
## 4  533140
## 5  568093
## 6  632150
## 7  635665
## 8  512397
## 9  623295
## 10 589639
## 11 550287
## 12 550361
## 13 596193
## 14 464459
## 15 629627
## 16 599441
## 17 534034
## 18 585212
## 19 538892
## 20 542965
## 21 492777
## 22 572391
## 23 570411
## 24 640464
## 25 649553
## 26 570284
## 27 643925
## 28 608827
## 29 552988
## 30 510031
## 31 530528
## 32 635706
## 33 554431
## 34 620120
## 35 566342
## 36 548513
## 37 599057
## 38 474199
## 39 475130
## 40 576641
## 41 463777
## 42 654763
## 43 529922
## 44 599063
## 45 622296
## 46 493044
## 47 592414
## 48 575704
## 49 654981
## 50 575859
## 51 505722
## 52 517273
## 53 492286
## 54 636961
## 55 629717
## 56 502591
## 57 569820
## 58 591682
## 59 590502
## 60 559657
## 61 657187
## 62 625756
## 63 657173
## 64 509607
## 65 499467
## 66 561157
## 67 616453
## 68 630626
## 69 567195
## 70 527449
## 71 459381
## 72 595298
## 73 466907
## 74 589943
## 75 537281
## 76 580426
## 77 595581
## 78 616315
## 79 642329
## 80 503701
## 81 632961
## 82 473173
## 83 575030
## 84 621924
## 85 536346
## 86 520660
## 87 577992
## 88 571970
## 89 644226
## 90 523927
## 91 640784
## 92 503218
## 93 606730
nodes_G1 <- nodes_G1 %>% rowid_to_column("id")
nodes_G1
##    id  label
## 1   1 616050
## 2   2 599956
## 3   3 490041
## 4   4 533140
## 5   5 568093
## 6   6 632150
## 7   7 635665
## 8   8 512397
## 9   9 623295
## 10 10 589639
## 11 11 550287
## 12 12 550361
## 13 13 596193
## 14 14 464459
## 15 15 629627
## 16 16 599441
## 17 17 534034
## 18 18 585212
## 19 19 538892
## 20 20 542965
## 21 21 492777
## 22 22 572391
## 23 23 570411
## 24 24 640464
## 25 25 649553
## 26 26 570284
## 27 27 643925
## 28 28 608827
## 29 29 552988
## 30 30 510031
## 31 31 530528
## 32 32 635706
## 33 33 554431
## 34 34 620120
## 35 35 566342
## 36 36 548513
## 37 37 599057
## 38 38 474199
## 39 39 475130
## 40 40 576641
## 41 41 463777
## 42 42 654763
## 43 43 529922
## 44 44 599063
## 45 45 622296
## 46 46 493044
## 47 47 592414
## 48 48 575704
## 49 49 654981
## 50 50 575859
## 51 51 505722
## 52 52 517273
## 53 53 492286
## 54 54 636961
## 55 55 629717
## 56 56 502591
## 57 57 569820
## 58 58 591682
## 59 59 590502
## 60 60 559657
## 61 61 657187
## 62 62 625756
## 63 63 657173
## 64 64 509607
## 65 65 499467
## 66 66 561157
## 67 67 616453
## 68 68 630626
## 69 69 567195
## 70 70 527449
## 71 71 459381
## 72 72 595298
## 73 73 466907
## 74 74 589943
## 75 75 537281
## 76 76 580426
## 77 77 595581
## 78 78 616315
## 79 79 642329
## 80 80 503701
## 81 81 632961
## 82 82 473173
## 83 83 575030
## 84 84 621924
## 85 85 536346
## 86 86 520660
## 87 87 577992
## 88 88 571970
## 89 89 644226
## 90 90 523927
## 91 91 640784
## 92 92 503218
## 93 93 606730
# Creating an Edge List:
per_route_G1 <- qt1 %>%  
  group_by(Source, Target) %>%
  summarise(weight = n()) %>% 
  ungroup()
per_route_G1
## # A tibble: 979 x 3
##    Source Target weight
##    <chr>  <chr>   <int>
##  1 463777 459381      1
##  2 463777 466907      1
##  3 463777 473173      1
##  4 463777 503701      1
##  5 463777 520660      1
##  6 463777 523927      1
##  7 463777 527449      1
##  8 463777 536346      1
##  9 463777 537281      1
## 10 463777 567195      1
## # ... with 969 more rows
edges_G1 <- per_route_G1 %>% 
  left_join(nodes_G1, by = c("Source" = "label")) %>% 
  rename(from = id)

edges_G1 <- edges_G1 %>% 
  left_join(nodes_G1, by = c("Target" = "label")) %>% 
  rename(to = id)

edges_G1 <- select(edges_G1, from, to, weight)
edges_G1
## # A tibble: 979 x 3
##     from    to weight
##    <int> <int>  <int>
##  1    41    71      1
##  2    41    73      1
##  3    41    82      1
##  4    41    80      1
##  5    41    86      1
##  6    41    90      1
##  7    41    70      1
##  8    41    85      1
##  9    41    75      1
## 10    41    69      1
## # ... with 969 more rows
# Creating a Network:
routes_network_G1 <- network(edges_G1, vertex.attr = nodes_G1, matrix.type = "edgelist", ignore.eval = FALSE)
routes_network_G1
##  Network attributes:
##   vertices = 93 
##   directed = TRUE 
##   hyper = FALSE 
##   loops = FALSE 
##   multiple = FALSE 
##   bipartite = FALSE 
##   total edges= 979 
##     missing edges= 0 
##     non-missing edges= 979 
## 
##  Vertex attribute names: 
##     id label vertex.names 
## 
##  Edge attribute names: 
##     weight
# Graph 2:
Sources_G2 <- qt2 %>%
  distinct(Source) %>%
  rename(label = Source)

Targets_G2 <- qt2 %>%
  distinct(Target) %>%
  rename(label = Target)

# Creating a Node List:
nodes_G2 <- full_join(Sources_G2, Targets_G2, by = "label")
nodes_G2
##     label
## 1  563211
## 2  541017
## 3  572413
## 4  505965
## 5  629627
## 6  515794
## 7  585212
## 8  599441
## 9  582851
## 10 527597
## 11 534034
## 12 644830
## 13 488928
## 14 602912
## 15 477138
## 16 544615
## 17 534449
## 18 639051
## 19 572391
## 20 542965
## 21 635665
## 22 538892
## 23 464459
## 24 568093
## 25 604021
## 26 510031
## 27 552988
## 28 533094
## 29 606043
## 30 595057
## 31 634181
## 32 548320
## 33 563584
## 34 536953
## 35 620120
## 36 515799
## 37 656156
## 38 552439
## 39 546478
## 40 533024
## 41 499312
## 42 464563
## 43 546626
## 44 533141
## 45 471663
## 46 501047
## 47 472522
## 48 475811
## 49 590265
## 50 653390
## 51 573870
## 52 645210
## 53 564798
## 54 627390
## 55 561114
## 56 601492
## 57 487668
## 58 657173
## 59 625756
## 60 509607
## 61 499467
## 62 630626
## 63 536346
## 64 520660
## 65 527449
## 66 459381
## 67 595298
## 68 466907
## 69 577992
## 70 580426
## 71 595581
## 72 616315
## 73 503701
## 74 571970
## 75 644226
## 76 632961
## 77 473173
## 78 575030
## 79 621924
## 80 640784
## 81 567195
## 82 537281
## 83 523927
## 84 642329
## 85 589943
## 86 503218
## 87 606730
nodes_G2 <- nodes_G2 %>% rowid_to_column("id")
nodes_G2
##    id  label
## 1   1 563211
## 2   2 541017
## 3   3 572413
## 4   4 505965
## 5   5 629627
## 6   6 515794
## 7   7 585212
## 8   8 599441
## 9   9 582851
## 10 10 527597
## 11 11 534034
## 12 12 644830
## 13 13 488928
## 14 14 602912
## 15 15 477138
## 16 16 544615
## 17 17 534449
## 18 18 639051
## 19 19 572391
## 20 20 542965
## 21 21 635665
## 22 22 538892
## 23 23 464459
## 24 24 568093
## 25 25 604021
## 26 26 510031
## 27 27 552988
## 28 28 533094
## 29 29 606043
## 30 30 595057
## 31 31 634181
## 32 32 548320
## 33 33 563584
## 34 34 536953
## 35 35 620120
## 36 36 515799
## 37 37 656156
## 38 38 552439
## 39 39 546478
## 40 40 533024
## 41 41 499312
## 42 42 464563
## 43 43 546626
## 44 44 533141
## 45 45 471663
## 46 46 501047
## 47 47 472522
## 48 48 475811
## 49 49 590265
## 50 50 653390
## 51 51 573870
## 52 52 645210
## 53 53 564798
## 54 54 627390
## 55 55 561114
## 56 56 601492
## 57 57 487668
## 58 58 657173
## 59 59 625756
## 60 60 509607
## 61 61 499467
## 62 62 630626
## 63 63 536346
## 64 64 520660
## 65 65 527449
## 66 66 459381
## 67 67 595298
## 68 68 466907
## 69 69 577992
## 70 70 580426
## 71 71 595581
## 72 72 616315
## 73 73 503701
## 74 74 571970
## 75 75 644226
## 76 76 632961
## 77 77 473173
## 78 78 575030
## 79 79 621924
## 80 80 640784
## 81 81 567195
## 82 82 537281
## 83 83 523927
## 84 84 642329
## 85 85 589943
## 86 86 503218
## 87 87 606730
# Creating an Edge List:
per_route_G2 <- qt2 %>%  
  group_by(Source, Target) %>%
  summarise(weight = n()) %>% 
  ungroup()
per_route_G2
## # A tibble: 952 x 3
##    Source Target weight
##    <chr>  <chr>   <int>
##  1 464459 499467      1
##  2 464459 625756      1
##  3 464563 459381      1
##  4 464563 466907      1
##  5 464563 473173      1
##  6 464563 503701      1
##  7 464563 520660      1
##  8 464563 523927      1
##  9 464563 527449      1
## 10 464563 536346      1
## # ... with 942 more rows
edges_G2 <- per_route_G2 %>% 
  left_join(nodes_G2, by = c("Source" = "label")) %>% 
  rename(from = id)

edges_G2 <- edges_G2 %>% 
  left_join(nodes_G2, by = c("Target" = "label")) %>% 
  rename(to = id)

edges_G2 <- select(edges_G2, from, to, weight)
edges_G2
## # A tibble: 952 x 3
##     from    to weight
##    <int> <int>  <int>
##  1    23    61      1
##  2    23    59      1
##  3    42    66      1
##  4    42    68      1
##  5    42    77      1
##  6    42    73      1
##  7    42    64      1
##  8    42    83      1
##  9    42    65      1
## 10    42    63      1
## # ... with 942 more rows
# Creating a Network:
routes_network_G2 <- network(edges_G2, vertex.attr = nodes_G2, matrix.type = "edgelist", ignore.eval = FALSE)
routes_network_G2
##  Network attributes:
##   vertices = 87 
##   directed = TRUE 
##   hyper = FALSE 
##   loops = FALSE 
##   multiple = FALSE 
##   bipartite = FALSE 
##   total edges= 952 
##     missing edges= 0 
##     non-missing edges= 952 
## 
##  Vertex attribute names: 
##     id label vertex.names 
## 
##  Edge attribute names: 
##     weight
# Graph 3:
Sources_G3 <- qt3 %>%
  distinct(Source) %>%
  rename(label = Source)

Targets_G3 <- qt3 %>%
  distinct(Target) %>%
  rename(label = Target)

# Creating a Node List:
nodes_G3 <- full_join(Sources_G3, Targets_G3, by = "label")
nodes_G3
##     label
## 1  614761
## 2  538892
## 3  500813
## 4  493094
## 5  536003
## 6  521318
## 7  542649
## 8  572391
## 9  541619
## 10 544074
## 11 493652
## 12 516236
## 13 607386
## 14 629627
## 15 585212
## 16 534034
## 17 599441
## 18 542965
## 19 635665
## 20 568093
## 21 464459
## 22 570284
## 23 643925
## 24 649553
## 25 598006
## 26 612711
## 27 643411
## 28 610497
## 29 552988
## 30 578531
## 31 510031
## 32 657076
## 33 478754
## 34 575295
## 35 568284
## 36 508898
## 37 620120
## 38 536951
## 39 466976
## 40 628223
## 41 492701
## 42 584736
## 43 520084
## 44 529433
## 45 604113
## 46 514306
## 47 476813
## 48 657173
## 49 625756
## 50 509607
## 51 499467
## 52 561157
## 53 616453
## 54 640784
## 55 630626
## 56 567195
## 57 527449
## 58 459381
## 59 595298
## 60 466907
## 61 589943
## 62 537281
## 63 523927
## 64 580426
## 65 616315
## 66 503701
## 67 632961
## 68 473173
## 69 575030
## 70 503218
## 71 606730
## 72 577992
## 73 642329
## 74 621924
## 75 571970
## 76 595581
## 77 536346
## 78 520660
## 79 644226
nodes_G3 <- nodes_G3 %>% rowid_to_column("id")
nodes_G3
##    id  label
## 1   1 614761
## 2   2 538892
## 3   3 500813
## 4   4 493094
## 5   5 536003
## 6   6 521318
## 7   7 542649
## 8   8 572391
## 9   9 541619
## 10 10 544074
## 11 11 493652
## 12 12 516236
## 13 13 607386
## 14 14 629627
## 15 15 585212
## 16 16 534034
## 17 17 599441
## 18 18 542965
## 19 19 635665
## 20 20 568093
## 21 21 464459
## 22 22 570284
## 23 23 643925
## 24 24 649553
## 25 25 598006
## 26 26 612711
## 27 27 643411
## 28 28 610497
## 29 29 552988
## 30 30 578531
## 31 31 510031
## 32 32 657076
## 33 33 478754
## 34 34 575295
## 35 35 568284
## 36 36 508898
## 37 37 620120
## 38 38 536951
## 39 39 466976
## 40 40 628223
## 41 41 492701
## 42 42 584736
## 43 43 520084
## 44 44 529433
## 45 45 604113
## 46 46 514306
## 47 47 476813
## 48 48 657173
## 49 49 625756
## 50 50 509607
## 51 51 499467
## 52 52 561157
## 53 53 616453
## 54 54 640784
## 55 55 630626
## 56 56 567195
## 57 57 527449
## 58 58 459381
## 59 59 595298
## 60 60 466907
## 61 61 589943
## 62 62 537281
## 63 63 523927
## 64 64 580426
## 65 65 616315
## 66 66 503701
## 67 67 632961
## 68 68 473173
## 69 69 575030
## 70 70 503218
## 71 71 606730
## 72 72 577992
## 73 73 642329
## 74 74 621924
## 75 75 571970
## 76 76 595581
## 77 77 536346
## 78 78 520660
## 79 79 644226
# Creating an Edge List:
per_route_G3 <- qt3 %>%  
  group_by(Source, Target) %>%
  summarise(weight = n()) %>% 
  ungroup()
per_route_G3
## # A tibble: 606 x 3
##    Source Target weight
##    <chr>  <chr>   <int>
##  1 464459 499467      1
##  2 464459 625756      1
##  3 466976 459381      1
##  4 466976 466907      1
##  5 466976 473173      1
##  6 466976 503701      1
##  7 466976 523927      1
##  8 466976 527449      1
##  9 466976 537281      1
## 10 466976 571970      1
## # ... with 596 more rows
edges_G3 <- per_route_G3 %>% 
  left_join(nodes_G3, by = c("Source" = "label")) %>% 
  rename(from = id)

edges_G3 <- edges_G3 %>% 
  left_join(nodes_G3, by = c("Target" = "label")) %>% 
  rename(to = id)

edges_G3 <- select(edges_G3, from, to, weight)
edges_G3
## # A tibble: 606 x 3
##     from    to weight
##    <int> <int>  <int>
##  1    21    51      1
##  2    21    49      1
##  3    39    58      1
##  4    39    60      1
##  5    39    68      1
##  6    39    66      1
##  7    39    63      1
##  8    39    57      1
##  9    39    62      1
## 10    39    75      1
## # ... with 596 more rows
# Creating a Network:
routes_network_G3 <- network(edges_G3, vertex.attr = nodes_G3, matrix.type = "edgelist", ignore.eval = FALSE)
routes_network_G3
##  Network attributes:
##   vertices = 79 
##   directed = TRUE 
##   hyper = FALSE 
##   loops = FALSE 
##   multiple = FALSE 
##   bipartite = FALSE 
##   total edges= 606 
##     missing edges= 0 
##     non-missing edges= 606 
## 
##  Vertex attribute names: 
##     id label vertex.names 
## 
##  Edge attribute names: 
##     weight
# Graph 4:
Sources_G4 <- qt4 %>%
  distinct(Source) %>%
  rename(label = Source)

Targets_G4 <- qt4 %>%
  distinct(Target) %>%
  rename(label = Target)

# Creating a Node List:
nodes_G4 <- full_join(Sources_G4, Targets_G4, by = "label")
nodes_G4
##     label
## 1  636721
## 2  628320
## 3  546593
## 4  536906
## 5  483005
## 6  601496
## 7  580798
## 8  492850
## 9  639642
## 10 557269
## 11 579305
## 12 584457
## 13 516873
## 14 569329
## 15 544636
## 16 464579
## 17 482012
## 18 566580
## 19 657526
## 20 588172
## 21 585606
## 22 655963
## 23 541907
## 24 510031
## 25 552988
## 26 620120
## 27 571369
## 28 477374
## 29 585417
## 30 625756
## 31 461577
## 32 629826
## 33 618398
## 34 655265
## 35 588802
## 36 499177
## 37 611572
## 38 561157
## 39 509607
## 40 580237
## 41 482579
## 42 638734
## 43 596726
## 44 537816
## 45 557626
## 46 657173
## 47 558089
## 48 459726
## 49 499467
## 50 578749
## 51 492039
## 52 571670
## 53 616453
## 54 500336
## 55 605235
## 56 623468
## 57 611238
## 58 590595
## 59 521673
## 60 516393
## 61 645371
## 62 536346
## 63 567195
## 64 527449
## 65 459381
## 66 595298
## 67 466907
## 68 577992
## 69 537281
## 70 523927
## 71 595581
## 72 642329
## 73 503701
## 74 571970
## 75 644226
## 76 632961
## 77 473173
## 78 575030
## 79 630626
## 80 580426
## 81 616315
## 82 520660
## 83 589943
## 84 606730
## 85 621924
## 86 503218
## 87 640784
nodes_G4 <- nodes_G4 %>% rowid_to_column("id")
nodes_G4
##    id  label
## 1   1 636721
## 2   2 628320
## 3   3 546593
## 4   4 536906
## 5   5 483005
## 6   6 601496
## 7   7 580798
## 8   8 492850
## 9   9 639642
## 10 10 557269
## 11 11 579305
## 12 12 584457
## 13 13 516873
## 14 14 569329
## 15 15 544636
## 16 16 464579
## 17 17 482012
## 18 18 566580
## 19 19 657526
## 20 20 588172
## 21 21 585606
## 22 22 655963
## 23 23 541907
## 24 24 510031
## 25 25 552988
## 26 26 620120
## 27 27 571369
## 28 28 477374
## 29 29 585417
## 30 30 625756
## 31 31 461577
## 32 32 629826
## 33 33 618398
## 34 34 655265
## 35 35 588802
## 36 36 499177
## 37 37 611572
## 38 38 561157
## 39 39 509607
## 40 40 580237
## 41 41 482579
## 42 42 638734
## 43 43 596726
## 44 44 537816
## 45 45 557626
## 46 46 657173
## 47 47 558089
## 48 48 459726
## 49 49 499467
## 50 50 578749
## 51 51 492039
## 52 52 571670
## 53 53 616453
## 54 54 500336
## 55 55 605235
## 56 56 623468
## 57 57 611238
## 58 58 590595
## 59 59 521673
## 60 60 516393
## 61 61 645371
## 62 62 536346
## 63 63 567195
## 64 64 527449
## 65 65 459381
## 66 66 595298
## 67 67 466907
## 68 68 577992
## 69 69 537281
## 70 70 523927
## 71 71 595581
## 72 72 642329
## 73 73 503701
## 74 74 571970
## 75 75 644226
## 76 76 632961
## 77 77 473173
## 78 78 575030
## 79 79 630626
## 80 80 580426
## 81 81 616315
## 82 82 520660
## 83 83 589943
## 84 84 606730
## 85 85 621924
## 86 86 503218
## 87 87 640784
# Creating an Edge List:
per_route_G4 <- qt4 %>%  
  group_by(Source, Target) %>%
  summarise(weight = n()) %>% 
  ungroup()
per_route_G4
## # A tibble: 615 x 3
##    Source Target weight
##    <chr>  <chr>   <int>
##  1 464579 459381      1
##  2 464579 459726      1
##  3 464579 466907      1
##  4 464579 473173      1
##  5 464579 500336      1
##  6 464579 503701      1
##  7 464579 516393      1
##  8 464579 521673      1
##  9 464579 523927      1
## 10 464579 527449      1
## # ... with 605 more rows
edges_G4 <- per_route_G4 %>% 
  left_join(nodes_G4, by = c("Source" = "label")) %>% 
  rename(from = id)

edges_G4 <- edges_G4 %>% 
  left_join(nodes_G4, by = c("Target" = "label")) %>% 
  rename(to = id)

edges_G4 <- select(edges_G4, from, to, weight)
edges_G4
## # A tibble: 615 x 3
##     from    to weight
##    <int> <int>  <int>
##  1    16    65      1
##  2    16    48      1
##  3    16    67      1
##  4    16    77      1
##  5    16    54      1
##  6    16    73      1
##  7    16    60      1
##  8    16    59      1
##  9    16    70      1
## 10    16    64      1
## # ... with 605 more rows
# Creating a Network:
routes_network_G4 <- network(edges_G4, vertex.attr = nodes_G4, matrix.type = "edgelist", ignore.eval = FALSE)
routes_network_G4
##  Network attributes:
##   vertices = 87 
##   directed = TRUE 
##   hyper = FALSE 
##   loops = FALSE 
##   multiple = FALSE 
##   bipartite = FALSE 
##   total edges= 615 
##     missing edges= 0 
##     non-missing edges= 615 
## 
##  Vertex attribute names: 
##     id label vertex.names 
## 
##  Edge attribute names: 
##     weight
# Graph 5:
Sources_G5 <- qt5 %>%
  distinct(Source) %>%
  rename(label = Source)

Targets_G5 <- qt5 %>%
  distinct(Target) %>%
  rename(label = Target)

# Creating a Node List:
nodes_G5 <- full_join(Sources_G5, Targets_G5, by = "label")
nodes_G5
##     label
## 1  619322
## 2  594308
## 3  524153
## 4  483784
## 5  549840
## 6  477657
## 7  631903
## 8  573137
## 9  561819
## 10 530990
## 11 510031
## 12 552988
## 13 620120
## 14 590442
## 15 629769
## 16 461577
## 17 547205
## 18 549891
## 19 632485
## 20 657173
## 21 620947
## 22 492039
## 23 616453
## 24 483999
## 25 644754
## 26 525263
## 27 532852
## 28 625756
## 29 517649
## 30 509607
## 31 587437
## 32 623736
## 33 493358
## 34 561157
## 35 643087
## 36 569044
## 37 556592
## 38 585589
## 39 579218
## 40 567281
## 41 624532
## 42 499177
## 43 605235
## 44 641131
## 45 499467
## 46 654641
## 47 620076
## 48 652996
## 49 558930
## 50 469675
## 51 657035
## 52 590595
## 53 529694
## 54 528019
## 55 472749
## 56 550251
## 57 619245
## 58 584229
## 59 544444
## 60 555931
## 61 503218
## 62 536346
## 63 520660
## 64 567195
## 65 527449
## 66 459381
## 67 595298
## 68 466907
## 69 589943
## 70 577992
## 71 537281
## 72 523927
## 73 580426
## 74 595581
## 75 616315
## 76 642329
## 77 503701
## 78 571970
## 79 644226
## 80 632961
## 81 473173
## 82 575030
## 83 621924
## 84 640784
## 85 630626
## 86 606730
nodes_G5 <- nodes_G5 %>% rowid_to_column("id")
nodes_G5
##    id  label
## 1   1 619322
## 2   2 594308
## 3   3 524153
## 4   4 483784
## 5   5 549840
## 6   6 477657
## 7   7 631903
## 8   8 573137
## 9   9 561819
## 10 10 530990
## 11 11 510031
## 12 12 552988
## 13 13 620120
## 14 14 590442
## 15 15 629769
## 16 16 461577
## 17 17 547205
## 18 18 549891
## 19 19 632485
## 20 20 657173
## 21 21 620947
## 22 22 492039
## 23 23 616453
## 24 24 483999
## 25 25 644754
## 26 26 525263
## 27 27 532852
## 28 28 625756
## 29 29 517649
## 30 30 509607
## 31 31 587437
## 32 32 623736
## 33 33 493358
## 34 34 561157
## 35 35 643087
## 36 36 569044
## 37 37 556592
## 38 38 585589
## 39 39 579218
## 40 40 567281
## 41 41 624532
## 42 42 499177
## 43 43 605235
## 44 44 641131
## 45 45 499467
## 46 46 654641
## 47 47 620076
## 48 48 652996
## 49 49 558930
## 50 50 469675
## 51 51 657035
## 52 52 590595
## 53 53 529694
## 54 54 528019
## 55 55 472749
## 56 56 550251
## 57 57 619245
## 58 58 584229
## 59 59 544444
## 60 60 555931
## 61 61 503218
## 62 62 536346
## 63 63 520660
## 64 64 567195
## 65 65 527449
## 66 66 459381
## 67 67 595298
## 68 68 466907
## 69 69 589943
## 70 70 577992
## 71 71 537281
## 72 72 523927
## 73 73 580426
## 74 74 595581
## 75 75 616315
## 76 76 642329
## 77 77 503701
## 78 78 571970
## 79 79 644226
## 80 80 632961
## 81 81 473173
## 82 82 575030
## 83 83 621924
## 84 84 640784
## 85 85 630626
## 86 86 606730
# Creating an Edge List:
per_route_G5 <- qt5 %>%  
  group_by(Source, Target) %>%
  summarise(weight = n()) %>% 
  ungroup()
per_route_G5
## # A tibble: 285 x 3
##    Source Target weight
##    <chr>  <chr>   <int>
##  1 477657 459381      1
##  2 477657 466907      1
##  3 477657 473173      1
##  4 477657 499467      5
##  5 477657 503701      1
##  6 477657 527449      1
##  7 477657 561157      5
##  8 477657 561819      1
##  9 477657 567195      1
## 10 477657 571970      1
## # ... with 275 more rows
edges_G5 <- per_route_G5 %>% 
  left_join(nodes_G5, by = c("Source" = "label")) %>% 
  rename(from = id)

edges_G5 <- edges_G5 %>% 
  left_join(nodes_G5, by = c("Target" = "label")) %>% 
  rename(to = id)

edges_G5 <- select(edges_G5, from, to, weight)
edges_G5
## # A tibble: 285 x 3
##     from    to weight
##    <int> <int>  <int>
##  1     6    66      1
##  2     6    68      1
##  3     6    81      1
##  4     6    45      5
##  5     6    77      1
##  6     6    65      1
##  7     6    34      5
##  8     6     9      1
##  9     6    64      1
## 10     6    78      1
## # ... with 275 more rows
# Creating a Network:
routes_network_G5 <- network(edges_G5, vertex.attr = nodes_G5, matrix.type = "edgelist", ignore.eval = FALSE)
routes_network_G5
##  Network attributes:
##   vertices = 86 
##   directed = TRUE 
##   hyper = FALSE 
##   loops = FALSE 
##   multiple = FALSE 
##   bipartite = FALSE 
##   total edges= 285 
##     missing edges= 0 
##     non-missing edges= 285 
## 
##  Vertex attribute names: 
##     id label vertex.names 
## 
##  Edge attribute names: 
##     weight

Network Visualisation:

plot(routes_network, vertex.cex = 3, main = "Template")

plot(routes_network_G1, vertex.cex = 3, main = "Graph 1")

plot(routes_network_G2, vertex.cex = 3, main = "Graph 2")

plot(routes_network_G3, vertex.cex = 3, main = "Graph 3")

plot(routes_network_G4, vertex.cex = 3, main = "Graph 4")

plot(routes_network_G5, vertex.cex = 3, main = "Graph 5")

Interactive Network Analysis:

VisNetwork:

# Communication Channel:
# Weighted edges:
edges <- mutate(edges, width = weight/5 + 1)
edges_G1 <- mutate(edges_G1, width = weight/5 + 1)
edges_G2 <- mutate(edges_G2, width = weight/5 + 1)
edges_G3 <- mutate(edges_G3, width = weight/5 + 1)
edges_G4 <- mutate(edges_G4, width = weight/5 + 1)
edges_G5 <- mutate(edges_G5, width = weight/5 + 1)


# Interactive Graphs with visNetwork:
temp_com <- visNetwork(nodes, edges)%>% visIgraphLayout(layout = "layout_with_fr") %>% visEdges(arrows = "middle")
visPhysics(temp_com, stabilization = FALSE, enabled = FALSE)
g1_com <- visNetwork(nodes_G1, edges_G1)%>% visIgraphLayout(layout = "layout_with_fr") %>% visEdges(arrows = "middle")
visPhysics(g1_com, stabilization = FALSE, enabled = FALSE)
g2_com <- visNetwork(nodes_G2, edges_G2)%>% visIgraphLayout(layout = "layout_with_fr") %>% visEdges(arrows = "middle")
visPhysics(g2_com, stabilization = FALSE, enabled = FALSE)
g3_com <- visNetwork(nodes_G3, edges_G3)%>% visIgraphLayout(layout = "layout_with_fr") %>% visEdges(arrows = "middle")
visPhysics(g3_com, stabilization = FALSE, enabled = FALSE)
g4_com <- visNetwork(nodes_G4, edges_G4)%>% visIgraphLayout(layout = "layout_with_fr") %>% visEdges(arrows = "middle")
visPhysics(g4_com, stabilization = FALSE, enabled = FALSE)
g5_com <- visNetwork(nodes_G5, edges_G5)%>% visIgraphLayout(layout = "layout_with_fr") %>% visEdges(arrows = "middle")
visPhysics(g5_com, stabilization = FALSE, enabled = FALSE)

Network D3.js

# Network D3.js:
nodes_d3 <- mutate(nodes, id = id - 1)
edges_d3 <- mutate(edges, from = from - 1, to = to - 1)
forceNetwork(Links = edges_d3, Nodes = nodes_d3, Source = "from", Target = "to", 
             NodeID = "label", Group = "id", Value = "weight", 
             opacity = 1, fontSize = 16, zoom = TRUE)
## Links is a tbl_df. Converting to a plain data frame.
nodes_d3_g1 <- mutate(nodes_G1, id = id - 1)
edges_d3_g1 <- mutate(edges_G1, from = from - 1, to = to - 1)
forceNetwork(Links = edges_d3_g1, Nodes = nodes_d3_g1, Source = "from", Target = "to", 
             NodeID = "label", Group = "id", Value = "weight", 
             opacity = 1, fontSize = 16, zoom = TRUE)
## Links is a tbl_df. Converting to a plain data frame.
nodes_d3_g2 <- mutate(nodes_G2, id = id - 1)
edges_d3_g2 <- mutate(edges_G2, from = from - 1, to = to - 1)
forceNetwork(Links = edges_d3_g2, Nodes = nodes_d3_g2, Source = "from", Target = "to", 
             NodeID = "label", Group = "id", Value = "weight", 
             opacity = 1, fontSize = 16, zoom = TRUE)
## Links is a tbl_df. Converting to a plain data frame.
nodes_d3_g3 <- mutate(nodes_G3, id = id - 1)
edges_d3_g3 <- mutate(edges_G3, from = from - 1, to = to - 1)
forceNetwork(Links = edges_d3_g3, Nodes = nodes_d3_g3, Source = "from", Target = "to", 
             NodeID = "label", Group = "id", Value = "weight", 
             opacity = 1, fontSize = 16, zoom = TRUE)
## Links is a tbl_df. Converting to a plain data frame.
nodes_d3_g4 <- mutate(nodes_G4, id = id - 1)
edges_d3_g4 <- mutate(edges_G4, from = from - 1, to = to - 1)
forceNetwork(Links = edges_d3_g4, Nodes = nodes_d3_g4, Source = "from", Target = "to", 
             NodeID = "label", Group = "id", Value = "weight", 
             opacity = 1, fontSize = 16, zoom = TRUE)
## Links is a tbl_df. Converting to a plain data frame.
nodes_d3_g5 <- mutate(nodes_G5, id = id - 1)
edges_d3_g5 <- mutate(edges_G5, from = from - 1, to = to - 1)
forceNetwork(Links = edges_d3_g5, Nodes = nodes_d3_g5, Source = "from", Target = "to", 
             NodeID = "label", Group = "id", Value = "weight", 
             opacity = 1, fontSize = 16, zoom = TRUE)
## Links is a tbl_df. Converting to a plain data frame.

Skankey Network:

sankeyNetwork(Links = edges_d3, Nodes = nodes_d3, Source = "from", Target = "to", 
              NodeID = "label", Value = "weight", fontSize = 16, unit = "Node(s)")
## Links is a tbl_df. Converting to a plain data frame.
sankeyNetwork(Links = edges_d3_g1, Nodes = nodes_d3_g1, Source = "from", Target = "to", 
              NodeID = "label", Value = "weight", fontSize = 16, unit = "Node(s)")
## Links is a tbl_df. Converting to a plain data frame.
sankeyNetwork(Links = edges_d3_g2, Nodes = nodes_d3_g2, Source = "from", Target = "to", 
              NodeID = "label", Value = "weight", fontSize = 16, unit = "Node(s)")
## Links is a tbl_df. Converting to a plain data frame.
sankeyNetwork(Links = edges_d3_g3, Nodes = nodes_d3_g3, Source = "from", Target = "to", 
              NodeID = "label", Value = "weight", fontSize = 16, unit = "Node(s)")
## Links is a tbl_df. Converting to a plain data frame.
sankeyNetwork(Links = edges_d3_g4, Nodes = nodes_d3_g4, Source = "from", Target = "to", 
              NodeID = "label", Value = "weight", fontSize = 16, unit = "Node(s)")
## Links is a tbl_df. Converting to a plain data frame.
sankeyNetwork(Links = edges_d3_g4, Nodes = nodes_d3_g4, Source = "from", Target = "to", 
              NodeID = "label", Value = "weight", fontSize = 16, unit = "Node(s)")
## Links is a tbl_df. Converting to a plain data frame.